mirror of
https://github.com/github/codeql.git
synced 2026-05-27 01:21:23 +02:00
Implements `AstSig::Parameter` and `callableGetParameter(c, i)` in
`AstNodeImpl.qll`, following the C# template
(`csharp/.../ControlFlowGraph.qll:147-156`) rather than Java's
`Parameter() { none() }`.
Each Python parameter (positional, *args, keyword-only, **kwargs) now
becomes a CFG node at a stable position in the enclosing callable's
entry sequence. Defaults still evaluate at function-definition time
via `FunctionDefExpr.getDefault` / `LambdaExpr.getDefault`, so
`Parameter::getDefaultValue()` returns `none()` (the shared CFG
library calls this to model the missing-argument fallback, which
Python does not surface at the CFG level).
The bindings test now exercises parameters (the `py_expr_contexts(_, 4, ...)`
exclusion has been removed). A new `parameters.py` test case covers
positional, defaulted, vararg, kwarg, keyword-only, kitchen-sink,
method (self/cls), lambda, and PEP 570 positional-only parameters.
Several other test files were updated to annotate parameters that the
test had previously hidden (synthetic `.0` comprehension parameter,
method `self`, decorator `f`, etc.).
Verified:
- All 24 ControlFlow/evaluation-order tests still pass.
- CFG consistency query (`python/ql/consistency-queries/CfgConsistency.ql`)
shows zero violations on CPython.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
24 lines
717 B
Python
24 lines
717 B
Python
# Match-statement pattern bindings.
|
|
|
|
def f(subject): # $ cfgdefines=f cfgdefines=subject
|
|
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 # $ cfgdefines=x
|
|
y: int # $ cfgdefines=y
|
|
|