Commit cd703dc
Python: omit PEP 695 type-param names from FunctionDefExpr/ClassDefExpr children
PEP 695 type-param names (e.g. `T` in `def func[T]:` or `class Box[T]:`)
bind in an annotation scope that nests the function/class body, so
their AST scope is the inner function/class — not the enclosing scope
where the FunctionDefExpr/ClassDefExpr CFG node lives. Visiting them
as children created scope-crossing CFG edges (nonLocalStep violations:
96 across CPython).
Drop them from the children list; the legacy CFG omitted them too.
TypeAliasStmt is unaffected (its type-params share scope with the
alias's enclosing scope).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 350a68d commit cd703dc
2 files changed
Lines changed: 22 additions & 36 deletions
File tree
- python/ql
- lib/semmle/python/controlflow/internal
- test/library-tests/ControlFlow/bindings
Lines changed: 16 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1423 | 1423 | | |
1424 | 1424 | | |
1425 | 1425 | | |
1426 | | - | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
1427 | 1432 | | |
1428 | 1433 | | |
1429 | 1434 | | |
1430 | 1435 | | |
1431 | 1436 | | |
1432 | | - | |
1433 | | - | |
1434 | | - | |
1435 | | - | |
1436 | | - | |
1437 | | - | |
1438 | | - | |
1439 | | - | |
1440 | | - | |
1441 | | - | |
1442 | | - | |
1443 | 1437 | | |
1444 | 1438 | | |
1445 | | - | |
1446 | | - | |
1447 | | - | |
1448 | | - | |
1449 | | - | |
| 1439 | + | |
1450 | 1440 | | |
1451 | 1441 | | |
1452 | | - | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
1453 | 1449 | | |
1454 | 1450 | | |
1455 | 1451 | | |
1456 | 1452 | | |
1457 | 1453 | | |
1458 | | - | |
1459 | | - | |
1460 | | - | |
1461 | | - | |
1462 | | - | |
1463 | | - | |
1464 | | - | |
1465 | | - | |
1466 | | - | |
1467 | | - | |
1468 | | - | |
1469 | 1454 | | |
1470 | 1455 | | |
1471 | 1456 | | |
| |||
1486 | 1471 | | |
1487 | 1472 | | |
1488 | 1473 | | |
1489 | | - | |
1490 | | - | |
1491 | | - | |
| 1474 | + | |
1492 | 1475 | | |
1493 | | - | |
| 1476 | + | |
1494 | 1477 | | |
1495 | 1478 | | |
1496 | 1479 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
6 | 9 | | |
7 | | - | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
12 | | - | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| |||
0 commit comments