Skip to content
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

CompoundFields doesn't work well when a <xs:sequence> is nested in a <xs:choice> #1120

Open
sashkent3 opened this issue Feb 28, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@sashkent3
Copy link

sashkent3 commented Feb 28, 2025

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 tefra added the enhancement New feature or request label Mar 1, 2025
@sashkent3
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants