Skip to content

Commit

Permalink
refactor: improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed Aug 14, 2023
1 parent 4bb9a97 commit 5134e5f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions hcloud/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@


class BaseDomain:
__slots__ = ()
__slots__: tuple[str, ...] = ()

@classmethod
def from_dict(cls, data: dict): # type: ignore[no-untyped-def]
"""Convert a dict to domain object."""
supported_data = {k: v for k, v in data.items() if k in cls.__slots__}
return cls(**supported_data)

def __repr__(self) -> str:
kwargs = [f"{key}={getattr(self, key)!r}" for key in self.__slots__] # type: ignore[var-annotated]
kwargs = [f"{key}={getattr(self, key)!r}" for key in self.__slots__]
return f"{self.__class__.__qualname__}({', '.join(kwargs)})"


Expand All @@ -24,10 +25,9 @@ class DomainIdentityMixin:
def id_or_name(self) -> int | str:
if self.id is not None:
return self.id
elif self.name is not None:
if self.name is not None:
return self.name
else:
raise ValueError("id or name must be set")
raise ValueError("id or name must be set")


class Pagination(BaseDomain):
Expand Down

0 comments on commit 5134e5f

Please sign in to comment.