Skip to content

Commit

Permalink
Python 3.7 compat: don't use missing_ok kwarg
Browse files Browse the repository at this point in the history
This was added in Python 3.8.

Signed-off-by: Nick Stenning <[email protected]>
  • Loading branch information
nickstenning committed Jul 11, 2023
1 parent 340e76f commit 1a4922e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion python/cog/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ def cleanup(self) -> None:
# Note this is pathlib.Path, which cog.Path is a subclass of. A pathlib.Path object shouldn't make its way here,
# but both have an unlink() method, so may as well be safe.
elif isinstance(value, Path):
value.unlink(missing_ok=True)
try:
value.unlink()
except FileNotFoundError:
pass


def get_predict(predictor: Any) -> Callable:
Expand Down
9 changes: 7 additions & 2 deletions python/cog/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ def convert(self) -> Path:
return self._path

def unlink(self, missing_ok: bool = False) -> None:
if self._path and self._path.exists():
self._path.unlink(missing_ok=missing_ok)
if self._path:
# TODO: use unlink(missing_ok=...) when we drop Python 3.7 support.
try:
self._path.unlink()
except FileNotFoundError:
if not missing_ok:
raise

def __str__(self) -> str:
# FastAPI's jsonable_encoder will encode subclasses of pathlib.Path by
Expand Down

0 comments on commit 1a4922e

Please sign in to comment.