Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Python] set the right scope for comprehension variables
This closes #4260 test plan: test files included and also see how the same variables "v" now resolve to the same Local each time ``` $ semgrep-core -lang py -dump_named_ast python/metavar_iterator.py Pr( [DefStmt( ({ name=EN( Id(("test", ()), {id_hidden=false; id_resolved=Ref(None); id_type=Ref( None); id_constness=Ref(None); })); attrs=[]; tparams=[]; }, FuncDef( {fkind=(Function, ()); fparams=[]; frettype=None; fbody=FBStmt( Block( [ExprStmt( Comprehension(List, (N( Id(("v", ()), {id_hidden=false; id_resolved=Ref(Some((Local, 1))); id_type=Ref(None); id_constness=Ref(None); })), [CompFor((), PatId(("v", ()), {id_hidden=false; id_resolved=Ref(Some((Local, 1))); id_type=Ref(None); id_constness=Ref(None); }), (), N( Id(("iterator", ()), {id_hidden=false; id_resolved=Ref(None); id_type=Ref(None); id_constness=Ref( None); })))])), ()); ExprStmt( Comprehension(List, (Call( N( Id(("f", ()), {id_hidden=false; id_resolved=Ref(None); id_type=Ref(None); id_constness=Ref(None); })), [Arg( N( Id(("v", ()), {id_hidden=false; id_resolved=Ref(Some((Local, 2))); id_type=Ref(None); id_constness=Ref( None); })))]), [CompFor((), PatId(("v", ()), {id_hidden=false; id_resolved=Ref(Some((Local, 2))); id_type=Ref(None); id_constness=Ref(None); }), (), N( Id(("iterator", ()), {id_hidden=false; id_resolved=Ref(None); id_type=Ref(None); id_constness=Ref( None); })))])), ())])); })))]) ```
- Loading branch information
Showing
11 changed files
with
58 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def test(): | ||
|
||
#ERROR: match | ||
[v for v in iterator] | ||
|
||
#ok:redundant-iterator | ||
[f(v) for v in iterator] | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[$X for $X in $ITERATOR] |