Skip to content

Commit

Permalink
Hide private attributes from string representation
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiascode committed Mar 2, 2024
1 parent cff4e24 commit 457d829
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
1 change: 1 addition & 0 deletions tinytag/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def _pop_switch(name: str) -> bool:

def _print_tag(tag: TinyTag, formatting: str, header_printed: bool = False) -> bool:
data = tag._as_dict()
del data['images']
if formatting == 'json':
print(json.dumps(data))
return header_printed
Expand Down
2 changes: 1 addition & 1 deletion tinytag/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,5 +785,5 @@ def test_to_str() -> None:
"'mime_type': None, 'description': None}, 'back_cover': {'data': None, 'mime_type': None, "
"'description': None}, 'leaflet': {'data': None, 'mime_type': None, 'description': None}, "
"'media': {'data': None, 'mime_type': None, 'description': None}, 'other': {'data': None, "
"'mime_type': None, 'description': None}, 'extra': {}}, "
"'mime_type': None, 'description': None}, 'extra': {}}"
) in str(tag)
7 changes: 2 additions & 5 deletions tinytag/tinytag.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,10 @@ def is_supported(cls, filename: bytes | str | PathLike[Any]) -> bool:
return cls._get_parser_for_filename(filename) is not None

def __repr__(self) -> str:
return str(vars(self))
return str(self._as_dict())

def _as_dict(self) -> dict[str, Any]:
return {
k: v for k, v in self.__dict__.items()
if not k.startswith('_') and k != 'images'
}
return {k: v for k, v in self.__dict__.items() if not k.startswith('_')}

@classmethod
def _get_parser_for_filename(
Expand Down

0 comments on commit 457d829

Please sign in to comment.