Commit 117fc6b
Python: keep the Python 2 reading of
The previous commit read a comma-separated fourth child as a tuple of exception
types unconditionally. That is right for Python 3, but the default parser is
version-agnostic and also runs when extracting Python 2
(`CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION=2`, `--lang=2`), where
`except Exception, e:` really is the alias binding and the canonical idiom. In
that mode the change flipped `e` from a `Store` to a `Load` of an undefined
name and dropped the binding altogether.
So the separator token alone is not enough to decide: `as` binds an alias in
every version, a comma binds an alias under Python 2 and builds a tuple
otherwise. Chains of three or more are unaffected either way -- they are not
valid Python 2, and the default grammar rejects them, so `Module.py_ast` falls
back to tree-sitter.
The file-driven parser tests cannot express this; they run at the default
analysis version and there is no per-fixture way to change it. So
`tests/test_except_clause.py` drives `parser.parse` directly with the version
flipped, and pins all four combinations -- comma and `as`, Python 2 and 3, plus
the parenthesized form that must bind no alias in either. Removing the version
gate fails the Python 2 case.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>except A, e:
1 parent 896d8d7 commit 117fc6b
3 files changed
Lines changed: 82 additions & 6 deletions
File tree
- python
- extractor
- semmle/python/parser
- tests
- ql/lib/change-notes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
981 | 982 | | |
982 | 983 | | |
983 | 984 | | |
984 | | - | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
985 | 994 | | |
986 | 995 | | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | | - | |
991 | 996 | | |
992 | 997 | | |
993 | 998 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
0 commit comments