xsdata
xsdata copied to clipboard
`CompoundFields` doesn't work well when a `<xs:sequence>` is nested in a `<xs:choice>`
Consider the following schema
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element name="TheFirstInnerChoice" type="xs:string"></xs:element>
<xs:element name="TheSecondInnerChoice" type="xs:string"></xs:element>
</xs:sequence>
<xs:element name="TheFirstChoice" type="xs:string"></xs:element>
<xs:element name="TheSecondChoice" type="xs:string"></xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
When the CompoundFields option is enabled, the type of the choice field is:
tuple[
Union[
TheFirstInnerChoice,
TheSecondInnerChoice,
TheFirstChoice,
TheSecondChoice,
],
...,
]
The above is rather incorrect because the strict Python equivalent of the schema would be:
Union[
tuple[
TheFirstInnerChoice,
TheSecondInnerChoice
],
TheFirstChoice,
TheSecondChoice,
]
@tefra just to clarify, the problem is not only with the type-hinting. The following XML is (incorrectly) parsed without error by the code generated from the above schema:
<Root>
<TheFirstChoice>test</TheFirstChoice>
<TheSecondChoice>test</TheSecondChoice>
</Root>
I believe this should be considered a bug.