handle type annotations in nested functions correctly#7072
handle type annotations in nested functions correctly#7072youknowone merged 1 commit intoRustPython:mainfrom
Conversation
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@crates/codegen/src/symboltable.rs`:
- Around line 1137-1142: The matches expression that sets
should_save_annotation_block currently checks parent_scope_typ for
CompilerScope::Class, ::Module, and ::Function but omits
CompilerScope::AsyncFunction; update the matches to include
Some(CompilerScope::AsyncFunction) so async functions are treated the same as
normal functions when deciding to save/restore annotation blocks (referencing
the local variables should_save_annotation_block and parent_scope_typ in
symboltable.rs).
For example in the following code:
def foo(x: int, y: float):
def bar(q: int):
return q
pass
Make sure that `foo` type annotations are correctly propogated to
it's `__annotate__` and `__annotations__` attributes.
With this chage, we'll get:
>>>>> foo.__annotations__
{'x': <class 'int'>, 'y': <class 'float'>}
Previously annotations where 'lost', and we would get:
>>>>> foo.__annotations__
{}
890e8ed to
2c83511
Compare
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [ ] lib: cpython/Lib/typing.py dependencies:
dependent tests: (10 tests)
Legend:
|
For example in the following code:
Make sure that
footype annotations are correctly propogated to it's__annotate__and__annotations__attributes.With this chage, we'll get:
Previously annotations where 'lost', and we would get:
Summary by CodeRabbit