-
Notifications
You must be signed in to change notification settings - Fork 246
fix panic: Name not found in static scope of module __unknown__ #1987 #2021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a panic that occurred when the parser synthesized empty identifiers during error recovery (e.g., when reserved keywords like async are used as assignment targets). The fix routes these synthesized targets through anonymous bindings, allowing the RHS expressions to still be analyzed for diagnostics without attempting to bind non-existent names to the static scope.
Key changes:
- Modified the detection logic for synthesized names to check only for empty strings, not both empty strings and empty ranges
- Added early-return handling in
bind_single_name_assignto route empty identifiers through anonymous bindings - Updated
bind_target_nameto use the synthesized name check for determining whether to create anonymous or definition-based bindings - Added a regression test for keyword assignment errors
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pyrefly/lib/test/semantic_syntax_errors.rs | Adds regression test for keyword assignment (async = 1) to ensure parse errors are reported without panicking |
| pyrefly/lib/binding/target.rs | Implements safe handling for synthesized empty identifiers in both bind_target_name and bind_single_name_assign functions by routing them through anonymous bindings |
| crates/pyrefly_python/src/ast.rs | Simplifies is_synthesized_empty_name to check only for empty identifier strings, making it more robust for parser error recovery |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: pandas (https://github.com/pandas-dev/pandas)
- ::error file=pandas/core/indexing.py,line=1470,col=9,endLine=1470,endColumn=28,title=Pyrefly bad-override::Class member `_LocIndexer._convert_to_indexer` overrides parent class `_LocationIndexer` in an inconsistent manner%0A `_LocIndexer._convert_to_indexer` has type `BoundMethod[_LocIndexer, (self: _LocIndexer, key: Unknown, axis: int) -> ndarray[tuple[Any, ...], dtype[signedinteger[_NBitIntP]]] | ndarray[tuple[Any, ...], dtype[Any]] | dict[str, int | integer[Any]] | dict[str, tuple[Unknown, ...]] | dict[str, Unknown] | Unknown]`, which is not assignable to `BoundMethod[_LocIndexer, (self: _LocIndexer, key: Unknown, axis: int) -> Never]`, the type of `_LocationIndexer._convert_to_indexer`
+ ::error file=pandas/core/indexing.py,line=1470,col=9,endLine=1470,endColumn=28,title=Pyrefly bad-override::Class member `_LocIndexer._convert_to_indexer` overrides parent class `_LocationIndexer` in an inconsistent manner%0A `_LocIndexer._convert_to_indexer` has type `BoundMethod[_LocIndexer, (self: _LocIndexer, key: Unknown, axis: int) -> int | ndarray[tuple[int], dtype[Any]] | ndarray[tuple[Any, ...], dtype[signedinteger[_NBitIntP]]] | ndarray[tuple[Any, ...], dtype[Any]] | slice[int, int, Any] | slice[Any, Any, Any] | dict[str, int | integer[Any]] | dict[str, tuple[Unknown, ...]] | dict[str, Unknown] | Unknown]`, which is not assignable to `BoundMethod[_LocIndexer, (self: _LocIndexer, key: Unknown, axis: int) -> Never]`, the type of `_LocationIndexer._convert_to_indexer`
|
stroxler
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review automatically exported from Phabricator review in Meta.
Summary
Fixes #1987
Fixes #2047
Implemented safe handling for parser-synthesized targets so keyword assignments no longer panic.
treat all empty identifiers as synthesized so later passes skip binding logic.
route synthesized lvalues and empty Identifiers through anonymous bindings, and short-circuit bind_single_name_assign when parser recovery produces an empty target, ensuring we still analyze RHS expressions without touching static scopes.
Test Plan
added regression test covering async = 1 and documented Ruff’s diagnostic wording.