File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
test/query-tests/Statements/general Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 1212 */
1313
1414import python
15- private import LegacyPointsTo
15+ private import semmle.python.ApiGraphs
1616
17- predicate originIsLocals ( ControlFlowNodeWithPointsTo n ) {
18- n . pointsTo ( _ , _ , Value :: named ( "locals" ) .getACall ( ) )
17+ predicate originIsLocals ( ControlFlowNode n ) {
18+ API :: builtin ( "locals" ) .getReturn ( ) . getAValueReachableFromSource ( ) . asCfgNode ( ) = n
1919}
2020
2121predicate modification_of_locals ( ControlFlowNode f ) {
3737 // in module level scope `locals() == globals()`
3838 // see https://docs.python.org/3/library/functions.html#locals
3939 // FP report in https://github.com/github/codeql/issues/6674
40- not a .getScope ( ) instanceof ModuleScope
40+ not a .getScope ( ) instanceof Module and
41+ // in class level scope `locals()` reflects the class namespace,
42+ // so modifications do take effect.
43+ not a .getScope ( ) instanceof Class
4144select a , "Modification of the locals() dictionary will have no effect on the local variables."
Original file line number Diff line number Diff line change @@ -174,3 +174,9 @@ def assert_ok(seq):
174174# False positive. ODASA-8042. Fixed in PR #2401.
175175class false_positive :
176176 e = (x for x in [])
177+
178+ # In class-level scope `locals()` reflects the class namespace,
179+ # so modifications do take effect.
180+ class MyClass :
181+ locals ()['x' ] = 43 # OK
182+ y = x
You can’t perform that action at this time.
0 commit comments