Files
codeql/python/ql/test/library-tests/ControlFlow/bindings/match_pattern.py
Copilot 336c7a44a8 Python: add CFG-binding gap tests (red)
Adds inline-expectation tests for the new shared CFG implementation in
python/ql/lib/semmle/python/controlflow/internal/AstNodeImpl.qll,
covering every Python binding construct that introduces a variable.

The test files use MISSING: annotations to record bindings whose
defining Name AST node is *not* currently reachable from the new CFG.
These are the 'red' half of red-green commit pairs: subsequent commits
will extend AstNodeImpl to cover each construct and remove the
corresponding MISSING: marker.

Confirmed-broken categories:
- Import aliases (from x import a)
- Annotated assignment (x: int = 1)
- Exception handler (except E as e)
- Match patterns (case x, case [a,b], case ... as v)
- PEP 695 type params (def f[T], class C[T])

Confirmed-working (no MISSING:):
- Compound targets, with-as, comprehensions, decorated def/class,
  walrus, starred.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-26 16:32:42 +00:00

24 lines
716 B
Python

# Match-statement pattern bindings.
def f(subject): # $ cfgdefines=f
match subject:
case x: # $ MISSING: cfgdefines=x
pass
case [a, b]: # $ MISSING: cfgdefines=a MISSING: cfgdefines=b
pass
case {"k": v}: # $ MISSING: cfgdefines=v
pass
case Point(p, q): # $ MISSING: cfgdefines=p MISSING: cfgdefines=q
pass
case [_, *rest]: # $ MISSING: cfgdefines=rest
pass
case (1 | 2) as n: # $ MISSING: cfgdefines=n
pass
class Point: # $ cfgdefines=Point
__match_args__ = ("x", "y") # $ cfgdefines=__match_args__
x: int # $ MISSING: cfgdefines=x
y: int # $ MISSING: cfgdefines=y