◐ Shell
clean mode source ↗

Fix symbol table sub_table desync for non-simple annotation targets by youknowone · Pull Request #7300 · RustPython/RustPython

added 2 commits

March 2, 2026 11:07
Non-simple annotations (subscript/attribute/parenthesized targets like
`a[0]: expr`) were scanned in the annotation scope during symbol table
analysis, creating sub_tables for any comprehensions. But codegen only
compiles simple name annotations into __annotate__, so those sub_tables
were never consumed. This caused subsequent simple annotations'
comprehension sub_tables to get the wrong index, resulting in
"the symbol 'X' must be present in the symbol table" errors.

Fix: skip entering annotation scope for non-simple annotations since
they are never compiled into __annotate__.
Fix cspell "desynchronize" warning and validate yield/await/named/async
comprehension expressions in non-simple annotations without creating
annotation scopes.

coderabbitai[bot]

@youknowone

This was referenced

Mar 16, 2026

youknowone added a commit to youknowone/RustPython that referenced this pull request

Mar 22, 2026
…ustPython#7300)

* Fix symbol table sub_table desync for non-simple annotation targets

Non-simple annotations (subscript/attribute/parenthesized targets like
`a[0]: expr`) were scanned in the annotation scope during symbol table
analysis, creating sub_tables for any comprehensions. But codegen only
compiles simple name annotations into __annotate__, so those sub_tables
were never consumed. This caused subsequent simple annotations'
comprehension sub_tables to get the wrong index, resulting in
"the symbol 'X' must be present in the symbol table" errors.

Fix: skip entering annotation scope for non-simple annotations since
they are never compiled into __annotate__.

* Validate forbidden expressions in non-simple annotation targets

Fix cspell "desynchronize" warning and validate yield/await/named/async
comprehension expressions in non-simple annotations without creating
annotation scopes.

* Restore in_annotation flag before propagating error