Python: visit function parameter and return annotations in new CFG#21943
Merged
yoff merged 0 commit intoJun 29, 2026
Merged
Conversation
yoff
force-pushed
the
yoff/python-cfg-modelling-exceptions
branch
from
June 4, 2026 22:13
c34dc45 to
f79f239
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
from
June 4, 2026 22:13
8a5ed32 to
96099ce
Compare
yoff
force-pushed
the
yoff/python-cfg-modelling-exceptions
branch
from
June 5, 2026 08:12
f79f239 to
b783ed6
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
from
June 5, 2026 08:12
96099ce to
709566e
Compare
yoff
force-pushed
the
yoff/python-cfg-modelling-exceptions
branch
from
June 18, 2026 13:17
b783ed6 to
158fb5b
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
from
June 18, 2026 13:17
038c537 to
537d704
Compare
yoff
force-pushed
the
yoff/python-cfg-modelling-exceptions
branch
from
June 18, 2026 15:12
158fb5b to
9c1d64b
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
from
June 18, 2026 15:12
537d704 to
19436d2
Compare
yoff
force-pushed
the
yoff/python-cfg-modelling-exceptions
branch
from
June 18, 2026 15:18
9c1d64b to
cada7e9
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
from
June 18, 2026 15:18
19436d2 to
08e2f37
Compare
yoff
force-pushed
the
yoff/python-cfg-modelling-exceptions
branch
from
June 22, 2026 11:56
cada7e9 to
7d5fd6b
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
from
June 22, 2026 11:56
08e2f37 to
8a0f3e9
Compare
yoff
force-pushed
the
yoff/python-cfg-modelling-exceptions
branch
from
June 22, 2026 12:28
7d5fd6b to
8e79ca5
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
2 times, most recently
from
June 22, 2026 12:45
59c80eb to
e842264
Compare
yoff
force-pushed
the
yoff/python-cfg-modelling-exceptions
branch
from
June 22, 2026 12:45
8e79ca5 to
3e5256d
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
from
June 22, 2026 13:47
e842264 to
8933010
Compare
yoff
force-pushed
the
yoff/python-cfg-modelling-exceptions
branch
from
June 22, 2026 13:47
3e5256d to
92e0331
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
from
June 24, 2026 08:04
8933010 to
a0a9ddf
Compare
yoff
changed the base branch from
yoff/python-cfg-modelling-exceptions
to
yoff/python-shared-cfg-dataflow-flip
June 24, 2026 08:05
yoff
force-pushed
the
yoff/python-shared-cfg-dataflow-flip
branch
from
June 24, 2026 08:18
93cae5f to
acb4a58
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
from
June 24, 2026 08:18
a0a9ddf to
c6ed878
Compare
yoff
force-pushed
the
yoff/python-shared-cfg-dataflow-flip
branch
from
June 24, 2026 08:46
acb4a58 to
5081d81
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
from
June 24, 2026 08:46
c6ed878 to
8189cd2
Compare
yoff
force-pushed
the
yoff/python-shared-cfg-dataflow-flip
branch
from
June 25, 2026 22:20
5081d81 to
4cbe7ae
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
2 times, most recently
from
June 25, 2026 23:08
683b96a to
d3d6a3d
Compare
yoff
force-pushed
the
yoff/python-shared-cfg-dataflow-flip
branch
2 times, most recently
from
June 29, 2026 11:40
62f34d5 to
44b8aad
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
from
June 29, 2026 11:40
d3d6a3d to
158147b
Compare
yoff
force-pushed
the
yoff/python-cfg-parameter-annotations
branch
from
June 29, 2026 13:25
158147b to
9ce906b
Compare
yoff
force-pushed
the
yoff/python-shared-cfg-dataflow-flip
branch
from
June 29, 2026 13:25
44b8aad to
9ce906b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #21937 (and the broader new-CFG stack: #21921, #21923, #21925).
Root cause. The new control flow graph (
semmle.python.controlflow.internal.Cfg, introduced in #21921) did not emit CFG nodes for parameter type annotations or for the return-type annotation on function definitions. The legacy CFG emitted both.LocalSources::annotatedInstance(and a small handful of framework models) walk the parameter-annotation expression via its CFG node to identify that a parameter receives an instance of the annotated class, so after the dataflow flip (#21925) annotation-based parameter tracking was silently broken.Fix. Extend
FunctionDefExpr.getChildto visit each annotation as a child of the function-def expression, in CPython evaluation order: positional parameter annotations,*argsannotation, keyword-only parameter annotations,**kwargsannotation, then the return annotation. Lambda expressions have no annotations in Python syntax, soLambdaExpris unchanged. PEP 695 type parameters remain out of scope (they belong to the inner annotation scope, not the enclosing CFG).Results.
Depends()receivers, Pydantic request bodies, StarletteWebSockethandlers, and the experimental call-graph type-annotation test all detect again.CWE-022-PathInjectionregains the lostfastapi_path_injection.py:26-27flow path throughfile_handler: FileHandler = Depends().taint_test.py:41,55).Stack: #21921 (P3) → #21923 (P4) → #21925 (Flip) → #21937 (CFG-Exc) → this.