-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Type hints for compound fields #858
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #858 +/- ##
==========================================
- Coverage 99.89% 99.89% -0.01%
==========================================
Files 104 104
Lines 9296 9295 -1
Branches 2077 2078 +1
==========================================
- Hits 9286 9285 -1
Misses 3 3
Partials 7 7
☔ View full report in Codecov by Sentry. |
b04f946
to
653bec5
Compare
653bec5
to
2772c6c
Compare
The change breaks several W3C tests (mostly "XmlContextError: Xml type 'Elements' does not support typing: ..."). |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
W3C tests pass now. Not sure what to do with sample test as these are not included in the CI of this package and seem to be broken at the moment (since this commit). |
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.
This is brilliant!!!
Obviously you had to dig very deep, I was amazed how simple the solution was, I always thought I would have to do a lot of refactoring to support this. The samples repo 🤦 was updated to reflect some changes from another feature pr, sorry about that I checked it manually and everything works as expected!
Thank you very much for this contribution
📒 Description
Compound fields are no longer type-hinted as
list[object]
.Instead, the type hints of compound fields now reflect the types in the corresponding
<xsd:choice>
definition.Resolves #857
🔗 What I've Done
xsdata/codegen/handlers/create_compound_fields.py
such that it passes a de-duplicated list comprising the types of the combined choices as type hints.tests/codegen/handlers/test_create_compound_fields.py
accordingly.tests/fixtures/compound/models.py
accordingly.XmlParser
, I had to reorder the logic inXmlVar.is_element
/XmlVar.is_elements
determination such thatXmlType.ELEMENTS
is picked up beforeXmlType.ELEMENT
.XmlVarBuilder.is_valid()
such thatobject
is allowed to be listed along with other types in aUnion
for XML typeXmlType.ELEMENTS
.This is useful to get proper type hinting when working with xsdata-generated code in an IDE.
💬 Comments
Are there additional tests needed explicitly covering this feature?
🛫 Checklist