Conversation
HanpuLi
force-pushed
the
fix/enum-nested-default-annotation
branch
from
September 19, 2026 13:44
b19c612 to
d75c01f
Compare
HanpuLi
force-pushed
the
fix/enum-nested-default-annotation
branch
from
September 20, 2026 16:50
f7c7770 to
f1702dc
Compare
This branch has not been deployed
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 #402.
The import hook injects annotation checks into method bodies, but method bodies do not inherit the containing class namespace. An annotation such as
value: NestedEnumis valid while the class body is being built, then becomes an unresolved bare name when the instrumented method is called.Track direct nested class names while transforming the class body and resolve those names through the implicit
__class__closure in method annotations. The class body is pre-scanned, so explicit/forward annotations also work when the referenced nested class is declared later in the class body. Module/global names remain unchanged.The regression coverage includes the nested
Enumcase from #402, an invalid value that must still raiseTypeCheckError, and a forward reference to a nested enum declared later in the class body. The existing separate@typecheckedlimitation remains xfailed and documented.Local verification:
coverage run -m pytest: 543 passed, 5 skipped, 6 xfailedpre-commit run --all-files: passed (including the project's mypy hook)sphinx-build -W -n docs <tmpdir>: passedgit diff --checkChecklist