mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
Python: Teach py/unused-local-variable about nonlocal.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
| variables_test.py:32:9:32:12 | test | The value assigned to local variable 'test' is never used. |
|
||||
@@ -0,0 +1 @@
|
||||
Variables/UnusedLocalVariable.ql
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
# FPs involving nonlocal
|
||||
|
||||
def nonlocal_fp():
|
||||
test = False
|
||||
def set_test():
|
||||
nonlocal test
|
||||
test = True
|
||||
set_test()
|
||||
if test:
|
||||
print("Test is set.")
|
||||
|
||||
nonlocal_fp()
|
||||
|
||||
def nonlocal_fp2():
|
||||
test = False
|
||||
|
||||
def set_test():
|
||||
nonlocal test
|
||||
test = True
|
||||
set_test()
|
||||
result = 5
|
||||
if not test:
|
||||
return
|
||||
return result
|
||||
|
||||
def not_fp():
|
||||
test = False
|
||||
def nonlocal_test():
|
||||
nonlocal test
|
||||
def set_test():
|
||||
test = True
|
||||
nonlocal_test()
|
||||
set_test()
|
||||
if test:
|
||||
print("Test is set.")
|
||||
Reference in New Issue
Block a user