mirror of
https://github.com/github/codeql.git
synced 2026-05-02 20:25:13 +02:00
Python: Teach py/unreachable-statement about contextlib.suppress.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Statements/UnreachableCode.ql
|
||||
31
python/ql/test/3/query-tests/Statements/unreachable_suppressed/test.py
Executable file
31
python/ql/test/3/query-tests/Statements/unreachable_suppressed/test.py
Executable file
@@ -0,0 +1,31 @@
|
||||
from contextlib import suppress
|
||||
|
||||
def raises_exception():
|
||||
raise Exception("This will be suppressed")
|
||||
|
||||
def foo():
|
||||
test = False
|
||||
with suppress(Exception):
|
||||
raises_exception()
|
||||
test = True
|
||||
if test:
|
||||
return
|
||||
print("An exception was raised") # FP: not reached
|
||||
|
||||
foo()
|
||||
|
||||
def bar(x):
|
||||
test = False
|
||||
try:
|
||||
if x:
|
||||
raise Exception("Bar")
|
||||
test = True
|
||||
except Exception:
|
||||
pass
|
||||
if test:
|
||||
print("Test was set")
|
||||
return
|
||||
print("Test was not set")
|
||||
|
||||
bar(True)
|
||||
bar(False)
|
||||
Reference in New Issue
Block a user