-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Update _models.py to handle Python 3.14 #2705
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
base: main
Are you sure you want to change the base?
Conversation
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| discriminator_field=discriminator_field_name, | ||
| discriminator_alias=discriminator_alias, | ||
| ) | ||
| cast(CachedDiscriminatorType, union).__discriminator__ = details | ||
| cast(CachedDiscriminatorType, Annotated[union, details]) |
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.
Restore caching of union discriminator metadata
The new code replaces cast(CachedDiscriminatorType, union).__discriminator__ = details with a bare cast(CachedDiscriminatorType, Annotated[union, details]). This only constructs an Annotated type and discards it, so the union instance never receives a __discriminator__ attribute. Subsequent calls to _build_discriminated_union_meta will therefore never hit the isinstance(union, CachedDiscriminatorType) fast path and tests that expect UnionType.__discriminator__ to exist (e.g. tests/test_models.py::test_discriminated_unions_invalid_data_uses_cache) will fail. Either the attribute assignment needs to be restored or the rest of the code must be updated to read metadata from the Annotated type instead.
Useful? React with 👍 / 👎.
|
Thanks for this PR. I think it’s quite urgent since the current OpenAI API isn’t working on Python 3.14 because of this issue. |
|
Thanks for the PR but this isn't the correct fix, the places that read the |
Would you like for me to do so? |
Changes being requested
Please using
Annotated[Union]with Python 3.14Additional context & links
Fixed #2704 to work properly with Python 3.14