Close descriptor after reading file.
This change has been motivated by below ResourceWarning Python3
is emitting when using this library:
ResourceWarning: unclosed file <_io.TextIOWrapper name='.../site-packages/os_service_types/data/service-types.json' mode='r' encoding='UTF-8'>
return json.load(open(os.path.join(DATA_DIR, filename), 'r'))
Change-Id: Id86cdedab44bf4096185ced2ed6b9379a71bc3e1
This commit is contained in:
@@ -21,5 +21,10 @@ DATA_DIR = os.path.dirname(__file__)
|
||||
|
||||
|
||||
def read_data(filename):
|
||||
"""Return data that is shipped inside the python package."""
|
||||
return json.load(open(os.path.join(DATA_DIR, filename), 'r'))
|
||||
"""Return data that is shipped inside the Python package.
|
||||
|
||||
"""
|
||||
|
||||
filepath = os.path.join(DATA_DIR, filename)
|
||||
with open(filepath, 'r') as fd:
|
||||
return json.load(fd)
|
||||
|
||||
Reference in New Issue
Block a user