Fix __qualname__ of compiler-generated __annotate__ functions - #8498
Fix __qualname__ of compiler-generated __annotate__ functions#8498kyokuping wants to merge 1 commit into
Conversation
Assisted-by: Codex:5.6-sol
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe compiler now passes annotated function names into annotation scopes. Qualified-name generation uses optional function names and preserves standard behavior for other scopes. ChangesAnnotation Scope Qualified Names
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [ ] lib: cpython/Lib/typing.py dependencies:
dependent tests: (19 tests)
Legend:
|
Assisted-by: Codex:5.6-sol
Summary
Under PEP 649, Python creates a generated
__annotate__function at compile time. This function holds the deferred annotation expressions for a function or class. Its__qualname__should match the qualified name of the annotated target, and__code__.co_qualnameshould match it too.In CPython, a similar issue was reported as python/cpython#137814 and resolved in PR python/cpython#137842.
In RustPython's codegen, annotation expression scopes were compiled in the enclosing scope, but the generated code object omitted the annotated target's own name when building the scope's qualified name. This caused both
__qualname__and__code__.co_qualnameon the generated__annotate__function to be incorrect.To resolve this, the codegen phase where the annotation expression scope is constructed has been modified so that the annotated target's name is included when forming the scope's qualified name. This keeps
__qualname__on the generated__annotate__function aligned with the annotated target and ensures__code__.co_qualnameremains consistent with CPython.As a result,
RegressionTests.test_annotate_qualnameinLib/test/test_type_annotations.pyis no longer marked as expectedFailure.Summary by CodeRabbit