From 5134e5fde55d22dd88f1afa4b5be0593bdf53a1b Mon Sep 17 00:00:00 2001 From: jo Date: Thu, 3 Aug 2023 15:31:57 +0200 Subject: [PATCH] refactor: improve code --- hcloud/core/domain.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hcloud/core/domain.py b/hcloud/core/domain.py index 21aed34..ec54ef3 100644 --- a/hcloud/core/domain.py +++ b/hcloud/core/domain.py @@ -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)})" @@ -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):