-
Notifications
You must be signed in to change notification settings - Fork 162
Add option to pythongen to use less inclusive types #464
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requestgenerator-dataclassesPython classes were generated by dataclass (we are mostly switching to Pydantic, though)Python classes were generated by dataclass (we are mostly switching to Pydantic, though)generator-python
Description
In the personinfo example (https://github.com/linkml/linkml/blob/main/examples/PersonSchema/personinfo/personinfo.py) we end up with
@dataclass
class Person(NamedThing):
...
has_employment_history: Optional[Union[Union[dict, "EmploymentEvent"], List[Union[dict, "EmploymentEvent"]]]] = empty_list()This is nice as it allows us to be very loose when instantiating objects. However, it is hard to read. And it also doesn't inform either us or our IDE of what the 'normalized' form of the object is
E,g,
if I do
p = Person('x', has_employment_history={'is_current': 1})it will normalize this from a single dict to a list of objects
>>> type(p.has_employment_history)
<class 'list'>I am not sure if we need this level of looseness in creation - it is handy to convert from a dict to an object but auto-converting objects to lists seems to encourage bad use. TBD: check if this is required for jsonld strategy
Should we:
- add an option to have stricter constructors in pythongen
- leave as is, and focus on pydanticgen (@kevinschaper ) as the preferred method for making an OM?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgenerator-dataclassesPython classes were generated by dataclass (we are mostly switching to Pydantic, though)Python classes were generated by dataclass (we are mostly switching to Pydantic, though)generator-python