Commit 2c7a1d2
Python: fix PEP 758
The grammar rule shared by both readings is
except_clause: 'except' [test [(',' | 'as') test]]
and `visit_except_clause` ignored the separator token, always treating the
fourth child as an alias to bind. So `except A, B:` extracted `B` as a Store
rather than a use, which is the Python 2 reading. Queries that reason about
whether a name is used then report false positives; `py/unused-import` flags
the import of `B` as unused.
The tree-sitter parser already extracts this as a tuple of exception types
(#20990), so the two parsers disagreed. `tests/parser/exceptions_relaxed.py`
is an unsuffixed parser test, which asserts the two parsers produce identical
ASTs; it fails without this change.
With the fix, the default parser reproduces the existing
`tests/parser/exceptions_new.expected` byte for byte, and of the 37 parser
test files only the two containing PEP 758 syntax change at all.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>except A, B: in the default parser1 parent 01755ec commit 2c7a1d2
3 files changed
Lines changed: 24 additions & 1 deletion
File tree
- python
- extractor
- semmle/python/parser
- tests/parser
- ql/lib/change-notes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
981 | 981 | | |
982 | 982 | | |
983 | 983 | | |
984 | | - | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
985 | 994 | | |
986 | 995 | | |
987 | 996 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
0 commit comments