pycoq icon indicating copy to clipboard operation
pycoq copied to clipboard

Give the caller `namedtuple`; factor out the need for dictionaries

Open quinn-dougherty opened this issue 2 years ago • 1 comments

passing dicts is good enough for the machine learning in python community, so it's good enough for us.

However, since we don't need quite the flexibility in configs the machine learning community needs, it looks like we can hardcode field names of config objects.

Passing around dictionaries will be annoying for the user in our case because what if a field is incorrect or missing?

From GeeksForGeeks

# Python code to demonstrate namedtuple()

from collections import namedtuple

# Declaring namedtuple()
Student = namedtuple('Student', ['name', 'age', 'DOB'])

# Adding values
S = Student('Nandini', '19', '2541997')

# Access using index
print("The Student age using index is : ", end="")
print(S[1])

# Access using name
print("The Student name using keyname is : ", end="")
print(S.name)

quinn-dougherty avatar Nov 05 '21 12:11 quinn-dougherty

Indeed, this how ppx_python works for now, see plans on #4 , cc @thierry-martinez ; also, all the objects we generate are coming from well-typed OCaml definitions so definitively we should generate Python types too.

ejgallego avatar Nov 05 '21 13:11 ejgallego