Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
3.14 regression with typing._eval_type() #136316
Copy link
Copy link
Closed
Labels
3.14bugs and security fixesbugs and security fixes3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Metadata
Metadata
Assignees
Labels
3.14bugs and security fixesbugs and security fixes3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
Bug description:
I'm in the process of adding 3.14 support to Pydantic. To evaluate type annotations, we make use of the private
typing._eval_type()function. In an ideal we shouldn't, but this is very hard to change now (and still, we need evaluate "standalone" type expressions for several reasons, e.g. to be able to haveTypeAdapter(list['ForwardReference'])working).In 3.13, the following works:
However, starting with 3.14, this raises:
Also explicitly passing
globalns=globals()in 3.14 doesn't work, astyping._eval_type()is setting the globals toNoneif a__forward_module__is present on theForwardRef:cpython/Lib/typing.py
Lines 432 to 447 in 5de7e3f
Which will affect all recursive calls to
_eval_type()fromevaluate_forward_ref().Sorry I couldn't find a repro not relying on this private function (nor I could get rid of the explicit
ForwardRefusage). Feel free to close as not planned, we can live without this in Pydantic (I hope).cc @JelleZijlstra
CPython versions tested on:
3.14
Operating systems tested on:
No response
Linked PRs