From 8ac4e4147ec63c1b8cbdab6e5da290307e77ec8a Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 17 Jan 2024 15:54:17 -0500 Subject: [PATCH] Refactor APIKey class to improve attribute access --- neon_client/client.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/neon_client/client.py b/neon_client/client.py index a636477..2cea171 100644 --- a/neon_client/client.py +++ b/neon_client/client.py @@ -23,6 +23,8 @@ class NeonClientException(requests.exceptions.HTTPError): pass + + class APIKey: """A Neon API key.""" @@ -47,12 +49,24 @@ class APIKey: @property def obj(self): + """The API key object.""" + if not self.__cached_obj: self.__cached_obj = self._data_model(**self._data) return self.__cached_obj + def __getattribute__(self, name): + """Get an attribute from the API key object or the API key data.""" + + try: + return super().__getattribute__(name) + except AttributeError: + return getattr(self.obj, name) + def __repr__(self): + """Return a string representation of the API key.""" + return repr(self.obj) @classmethod