Skip to content

Commit

Permalink
Avoid error in FileInfo repr due to permissions being None (#956)
Browse files Browse the repository at this point in the history
FileInfo.__repr__ was raising a TypeError due to the expectation that
permissions was never None, and the ":o" format string:

TypeError: unsupported format string passed to NoneType.__format__

At first I was surprised that Pyright didn't catch this, because
clearly dict.get can return None, but we were defining a _FileKwargs
TypedDict with a non-optional "permissions" field, so fix that too.

Fixes #955
  • Loading branch information
benhoyt committed Jun 16, 2023
1 parent cbaec52 commit 6fcda00
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ops/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
_StringOrPath = Union[str, pathlib.PurePosixPath, pathlib.Path]
_FileOrDir = Union['_File', '_Directory']
_FileKwargs = TypedDict('_FileKwargs', {
'permissions': int,
'permissions': Optional[int],
'last_modified': datetime.datetime,
'user_id': Optional[int],
'user': Optional[str],
Expand Down Expand Up @@ -2476,7 +2476,7 @@ def get_pebble_file_type(file: '_FileOrDir') -> pebble.FileType:
name=file.name,
type=get_pebble_file_type(file),
size=file.size if isinstance(file, _File) else None,
permissions=file.kwargs.get('permissions'),
permissions=file.kwargs.get('permissions') or 0,
last_modified=file.last_modified,
user_id=file.kwargs.get('user_id'),
user=file.kwargs.get('user'),
Expand Down

0 comments on commit 6fcda00

Please sign in to comment.