Skip to content

Commit

Permalink
fix(filehandler): Fix local files' opening mode
Browse files Browse the repository at this point in the history
With the LocalFileHandler, if the "mode" argument did not contain "b"
for binary mode explicitly, files would actually be opened in text mode.
This clashed with the type annotations and documentation.

This commit always explicitly enables binary mode when opening the
underlying file.
  • Loading branch information
ewuerger authored and Wuestengecko committed Oct 25, 2023
1 parent ffab485 commit 9c92750
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions capellambse/filehandler/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ def open(
normpath = helpers.normalize_pure_path(filename)
if "w" not in mode or self.__transaction is None:
path = self.path / normpath
return t.cast(t.BinaryIO, path.open(mode))
return path.open("rb")

if normpath in self.__transaction:
raise RuntimeError(
f"File already written in this transaction: {normpath}"
)
self.__transaction.add(normpath)
tmppath = _tmpname(normpath)
return t.cast(t.BinaryIO, (self.path / tmppath).open(mode))
return (self.path / tmppath).open("wb")

def get_model_info(self) -> ModelInfo:
assert isinstance(self.path, pathlib.Path)
Expand Down

0 comments on commit 9c92750

Please sign in to comment.