mirror of
https://github.com/github/codeql.git
synced 2026-06-19 11:51:08 +02:00
Add test for FP for py/should-use-with
This commit is contained in:
@@ -1 +1,2 @@
|
||||
| test.py:168:9:168:17 | Attribute() | Instance of context-manager class $@ is closed in a finally block. Consider using 'with' statement. | test.py:151:1:151:17 | Class CM | CM |
|
||||
| test.py:182:13:182:26 | Attribute() | Instance of context-manager class $@ is closed in a finally block. Consider using 'with' statement. | test.py:151:1:151:17 | Class CM | CM |
|
||||
|
||||
@@ -167,6 +167,20 @@ def no_with():
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
# Should use context manager, with the resource held in an instance attribute
|
||||
# (caught via instance-attribute type tracking).
|
||||
class HoldsCM(object):
|
||||
|
||||
def __init__(self):
|
||||
self.f = CM()
|
||||
|
||||
def no_with_attribute(self):
|
||||
try:
|
||||
self.f.write("Hello ")
|
||||
self.f.write(" World\n")
|
||||
finally:
|
||||
self.f.close()
|
||||
|
||||
#Assert without side-effect
|
||||
def assert_ok(seq):
|
||||
assert all(isinstance(element, (str, unicode)) for element in seq)
|
||||
|
||||
Reference in New Issue
Block a user