Ensure forward references are resolved correctly in Python3.14#543
Merged
agronholm merged 9 commits intoagronholm:masterfrom Feb 3, 2026
Merged
Ensure forward references are resolved correctly in Python3.14#543agronholm merged 9 commits intoagronholm:masterfrom
agronholm merged 9 commits intoagronholm:masterfrom
Conversation
Owner
|
Oh, nice! I had started working on this myself but I hadn't arrived at an actual fix yet, and got sidetracked with other projects. |
dionhaefner
commented
Jan 29, 2026
Owner
|
I'll do a proper review within a few days. |
agronholm
requested changes
Feb 2, 2026
Owner
agronholm
left a comment
There was a problem hiding this comment.
It would seem like you're mixing two different tasks here. Please send these fixes as separate PRs.
agronholm
requested changes
Feb 3, 2026
Owner
agronholm
left a comment
There was a problem hiding this comment.
Looks much better now. Just resolve the remaining comments and I'll approve.
Owner
|
Oh, and feel free to send a PR for that |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Fixes #536.
The bug was that Python 3.14's
ForwardRef.evaluate()method requires all referenced names to be available in the provided globals/locals dictionaries. When typeguard passed the caller's execution context (fromTypeCheckMemo) instead of the module where the type was defined, forward references to types that aren't available in that context could not be resolved. Instead we now check ifForwardRef.__forward_module__is defined, and letForwardRef.evaluate()with default arguments figure out the resolution (which does the right thing out of the box).Also had to fix an issue with unpacking
typing.Requiredsimilar toNotRequired, in order to fix the original issue with pydantic in #536 (confirmed fixed on my machine).Added a test that checks for both.
Checklist
If this is a user-facing code change, like a bugfix or a new feature, please ensure that
you've fulfilled the following conditions (where applicable):
tests/) added which would fail without your patchYou've updated the documentation (indocs/, in case of behavior changes or newfeatures)
docs/versionhistory.rst).If this is a trivial change, like a typo fix or a code reformatting, then you can ignore
these instructions.
Updating the changelog
If there are no entries after the last release, use
**UNRELEASED**as the version.If, say, your patch fixes issue #999, the entry should look like this:
* Fix big bad boo-boo in the pytest plugin (#999 <https://github.com/agronholm/typeguard/issues/999>_; PR by @yourgithubaccount)If there's no issue linked, just link to your pull request instead by updating the
changelog after you've created the PR.