Commit 7d9ae21
Python: test the Python 2 except reading through extraction, not a unit test
Replaces `tests/test_except_clause.py` with an extractor test, as suggested in
review. `python/ql/test/2/extractor-tests/relaxed_except` extracts a Python 2
file with `--lang=2` and pins, per handler, the types and whether the bound name
is a definition -- so it asserts the consequence a query sees, not the shape of
the AST. Removing the version gate from `visit_except_clause` makes it fail.
Doing it that way needed one extractor fix first. `populator.main` honours
`--lang` by calling `update_analysis_version`, but that only rebinds a global in
the process that parses the options; the extraction itself runs in an
`ExtractorPool`, and on macOS those workers are spawned rather than forked, so
they re-read `CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION` from the environment and
saw the default of 3. `--lang=2` therefore meant Python 2 on Linux and Python 3
on macOS. Setting the variable as well as the global makes the flag mean the
same thing on both, which is what lets the new test pin the Python 2 reading
anywhere. Real Python 2 extraction was never affected: the CodeQL action sets
that variable itself, and children inherit it.
Bumps the extractor version, which the fix in the first commit should have done.
Verified with codeql 2.26.3 and this branch's extractor patched into it:
`python/ql/test/2/extractor-tests` 10 passed (`hidden` fails identically on the
unpatched extractor, so it is not from this branch), and the py3 side is
unchanged -- `python/ql/test/query-tests/Imports` all 17 passed, which also
confirms the `relaxed_except*.py` query tests added earlier.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 117fc6b commit 7d9ae21
7 files changed
Lines changed: 55 additions & 72 deletions
File tree
- python
- extractor
- semmle
- tests
- ql/test/2/extractor-tests/relaxed_except
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
68 | 73 | | |
69 | 74 | | |
70 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
Lines changed: 26 additions & 0 deletions
| 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 | + | |
| 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 | + | |
0 commit comments