Skip to content

Commit

Permalink
Updates requested changes by iamfaisalkhan, Removes redundant close f…
Browse files Browse the repository at this point in the history
…rom cli.py, formats model.py with make format
  • Loading branch information
Trevor Gevers authored and Trevor Gevers committed Dec 9, 2024
1 parent f00015b commit 9b9dc61
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion modelscan/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def scan(
with open(settings_file_path, encoding="utf-8") as sf:
settings = parse(sf.read()).unwrap()
click.echo(f"Detected settings file. Using {settings_file_path}. \n")
sf.close()
else:
click.echo(
f"No settings file detected at {settings_file_path}. Using defaults. \n"
Expand Down
8 changes: 4 additions & 4 deletions modelscan/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class ModelDataEmpty(ValueError):
class Model:
_source: Path
_stream: Optional[IO[bytes]]
_should_close_stream: bool # Flag to control closing of file
_should_close_stream: bool # Flag to control closing of file
_context: Dict[str, Any]

def __init__(self, source: Union[str, Path], stream: Optional[IO[bytes]] = None):
self._source = Path(source)
self._stream = stream
self._should_close_stream = stream is None # Only close if opened
self._should_close_stream = stream is None # Only close if opened
self._context = {"formats": []}

def set_context(self, key: str, value: Any) -> None:
Expand All @@ -37,8 +37,8 @@ def close(self) -> None:
# Only close the stream if we opened a file (not for IO[bytes] objects passed in)
if self._stream and self._should_close_stream:
self._stream.close()
self._stream = None # Avoid double-closing
self._should_close_stream = False # Reset the flag
self._stream = None # Avoid double-closing
self._should_close_stream = False # Reset the flag

def __enter__(self) -> "Model":
return self.open()
Expand Down

0 comments on commit 9b9dc61

Please sign in to comment.