Skip to content

Commit 65fd2da

Browse files
authored
Fix unclosed file warnings (#107)
1 parent cf3f2d7 commit 65fd2da

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

petab/sbml.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,10 @@ def get_sbml_model(
442442
:return: The SBML document, model and reader
443443
"""
444444
if is_file_like(filepath_or_buffer) or is_url(filepath_or_buffer):
445-
handle = get_handle(filepath_or_buffer, mode='r').handle
445+
with get_handle(filepath_or_buffer, mode='r') as io_handle:
446+
data = load_sbml_from_string(''.join(io_handle.handle))
446447
# URL or already opened file, we will load the model from a string
447-
return load_sbml_from_string(''.join(handle))
448+
return data
448449

449450
return load_sbml_from_file(filepath_or_buffer)
450451

petab/yaml.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ def load_yaml(yaml_config: Union[Dict, Path, str]) -> Dict:
132132
if isinstance(yaml_config, dict):
133133
return yaml_config
134134

135-
handle = get_handle(yaml_config, mode='r').handle
136-
return yaml.safe_load(handle)
135+
with get_handle(yaml_config, mode='r') as io_handle:
136+
data = yaml.safe_load(io_handle.handle)
137+
return data
137138

138139

139140
def is_composite_problem(yaml_config: Union[Dict, str, Path]) -> bool:

0 commit comments

Comments
 (0)