Skip to content

Commit

Permalink
Clean up Entry
Browse files Browse the repository at this point in the history
  • Loading branch information
ingrinder committed Apr 13, 2024
1 parent 641dcd2 commit 76cfe31
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions archey/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,16 @@ def __init__(self, name: Optional[str] = None, value=None, options: Optional[dic

def __iter__(self) -> Self:
"""Best-effort set up of an iterable of value for inherited entries to use."""
try:
if isinstance(self.value, str):
raise TypeError
if isinstance(self.value, dict):
self._iter_value = iter(self.value.items())
else:
self._iter_value = iter(self.value)
except TypeError:
# e.g. int, str, None
if self.value:
self._iter_value = iter([self.value])
else:
# Make an empty iterable rather than `[None]`
self._iter_value = iter([])
if isinstance(self.value, (str, int)):
self._iter_value = iter([self.value])
elif isinstance(self.value, dict):
self._iter_value = iter(self.value.items())
elif self.value:
# Don't know what it is -- let `iter` deal with it.
self._iter_value = iter(self.value)
else:
# Make an empty iterable rather than `[None]`
self._iter_value = iter([])
return self

def __next__(self) -> ValueType:
Expand All @@ -78,8 +74,8 @@ def __next__(self) -> ValueType:
# If the value is "truthy" use `__str__`
if self.value:
return (self.name, str(self))
# Otherwise, `None`
return (self.name, None)
# Otherwise, just raise `StopIteration` immediately
raise StopIteration

def __str__(self) -> str:
"""Provide a sane default printable string representation of the entry"""
Expand Down

0 comments on commit 76cfe31

Please sign in to comment.