Use with statements to eliminate ResourceWarnings

This commit is contained in:
Thom Smith 2021-09-22 16:32:47 -04:00 committed by Ingy döt Net
parent 779bdb129e
commit 575d2f46db
16 changed files with 145 additions and 91 deletions

View file

@ -257,10 +257,12 @@ def test_constructor_types(data_filename, code_filename, verbose=False):
native1 = None
native2 = None
try:
native1 = list(yaml.load_all(open(data_filename, 'rb'), Loader=MyLoader))
with open(data_filename, 'rb') as file:
native1 = list(yaml.load_all(file, Loader=MyLoader))
if len(native1) == 1:
native1 = native1[0]
native2 = _load_code(open(code_filename, 'rb').read())
with open(code_filename, 'rb') as file:
native2 = _load_code(file.read())
try:
if native1 == native2:
return
@ -284,7 +286,8 @@ test_constructor_types.unittest = ['.data', '.code']
def test_subclass_blacklist_types(data_filename, verbose=False):
_make_objects()
try:
yaml.load(open(data_filename, 'rb').read(), MyFullLoader)
with open(data_filename, 'rb') as file:
yaml.load(file.read(), MyFullLoader)
except yaml.YAMLError as exc:
if verbose:
print("%s:" % exc.__class__.__name__, exc)