-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modernpython #18
Modernpython #18
Conversation
Signed-off-by: Guillaume Roger <[email protected]>
Signed-off-by: Guillaume Roger <[email protected]>
ef5fb0d
to
61b8a11
Compare
Signed-off-by: Guillaume Roger <[email protected]>
500cad9
to
9993451
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
@guillaume-alliander interesting work! I am working on something similar (albeit I am not using dataclass but BaseModel), and found out a few issues with recursive models across multiple files, which lead me to generate a single file: did you test the generated code? happy to help :) |
# the default value is either None or [] depending on the multiplicity. See also write_python_files | ||
# The default will be copied as-is, hence the possibility to have default or default_factory. | ||
if result in ["M:1", "M:0..1", "M:1..1", ""]: | ||
return ("Optional[str]", "default=None") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If think I understand why you don't have recursion errors: you are not using other dataclassess as attribute type.
Albeit this avoids any recursion and make validation faster, it does not exploit the full power of pydantic, and makes difficult to navigate the data.
I based this a lot on the current python serialization. As the recursion aspect was not there, it's not present in my classes :) You are correct that I do not use other dataclasses as attributes. It would be nice indeed. I am currently heavily using the generated classes, and adding dataclasses as possible attributes could have very interesting aspects. My final goal would be to load the graph in rdflib (to export to xml, json-ld, ttl... for free), and that could help. |
to keep simple and the parse easy, it may make completely sense! it is just more complex to navigate a linked object (you will have to search it by id through the full list of objects)
of course we want also to be able to import and export to different format, plus ideally make easy to manipulate / filter the objects via APIs (that's why we have been looking into pydantic and we tested the recursion support), beyond that, for us, also storage in a database (so adding also SQL Alchemy support) is an interesting feature. Maybe we can have a short call, exchange ideas, and see if there is a chance for a collaboration? |
Sure, that sounds great! To avoid sharing publicly email addresses, I found you on LinkedIn and will send a message here. |
@iripiri Would it be possible to get a review for this PR? More updates here will come, but this PR is a nicely self-contained. |
Sorry for the delay, the changes look good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Adding Python 3.9+ langpack, with pydantic dataclasses.
Those classes cannot be used directly with cimpy, but they do simplify quite a lot of coding. The class tree crawling is built into Base, profiles to which an attribute belongs are added to the attribute definition itself, json dump/parsing is built in.
Sonarcloud complains about code smells - those are logical, but fixing those would cause discrepancy with the style of the rest of the code, so I leave them as is for now. If that's not the best option, let me know.