Skip to content

Commit 5f438e4

Browse files
committed
python: exclude nonlocals from query
1 parent 9b7a20f commit 5f438e4

File tree

2 files changed

+1
-2
lines changed

2 files changed

+1
-2
lines changed

python/ql/src/Variables/UninitializedLocal.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Undefined
1515
import semmle.python.pointsto.PointsTo
1616

1717
predicate uninitialized_local(NameNode use) {
18-
exists(FastLocalVariable local | use.uses(local) or use.deletes(local) | not local.escapes()) and
18+
exists(FastLocalVariable local | use.uses(local) or use.deletes(local) | not local.escapes() and not local = any(Nonlocal nl).getAVariable()) and
1919
(
2020
any(Uninitialized uninit).taints(use) and
2121
PointsToInternal::reachableBlock(use.getBasicBlock(), _)

python/ql/test/query-tests/Variables/undefined/UninitializedLocal.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@
1111
| UninitializedLocal.py:163:7:163:7 | x | Local variable 'x' may be used before it is initialized. |
1212
| UninitializedLocal.py:176:16:176:16 | x | Local variable 'x' may be used before it is initialized. |
1313
| UninitializedLocal.py:178:16:178:16 | y | Local variable 'y' may be used before it is initialized. |
14-
| captured.py:8:15:8:17 | foo | Local variable 'foo' may be used before it is initialized. |
1514
| odasa3987.py:11:8:11:10 | var | Local variable 'var' may be used before it is initialized. |

0 commit comments

Comments
 (0)