77
88import abc
99import pathlib
10+ import types
1011import typing
1112import inspect
1213import uuid
@@ -281,23 +282,14 @@ def _get_attribute(
281282 self ,
282283 attribute : str ,
283284 * ,
284- local_default : object | None = None ,
285285 url : str | None = None ,
286286 ) -> object :
287287 """Retrieve an attribute for the given object.
288288
289- The argument 'local_default' refers to the value to return when
290- retrieving objects of this type via 'get'. In this case, if a key
291- is not present (likely due to the user specifying key=False on retrieval)
292- we do not want to attempt to retrieve the value from the server, as doing
293- so for every item would cause significant overhead. Instead we use this value.
294-
295289 Parameters
296290 ----------
297291 attribute : str
298292 name of attribute to retrieve
299- local_default : str | None, optional
300- if specified, the default value to return if the object is in 'local' mode.
301293 url : str | None, optional
302294 alternative URL to use for retrieval.
303295
@@ -319,7 +311,7 @@ def _get_attribute(
319311 return self ._staging [attribute ]
320312 except KeyError as e :
321313 if self ._local :
322- return local_default
314+ raise e
323315 # If the key is not in staging, but the object is not in offline mode
324316 # retrieve from the server and update cache instead
325317 if not _offline_state and (
@@ -338,9 +330,6 @@ def _get_attribute(
338330 )
339331 return self ._get (url = url )[attribute ]
340332 except KeyError as e :
341- if local_default :
342- return local_default
343-
344333 if self ._offline :
345334 raise AttributeError (
346335 f"A value for attribute '{ attribute } ' has "
@@ -740,9 +729,19 @@ def __str__(self) -> str:
740729
741730 def __repr__ (self ) -> str :
742731 _out_str = f"{ self .__class__ .__module__ } .{ self .__class__ .__qualname__ } ("
743- _out_str += ", " .join (
744- f"{ property } ={ getattr (self , property , 'N/A' )!r} "
745- for property in self ._properties
746- )
732+ _property_values : list [str ] = []
733+
734+ for property in self ._properties :
735+ try :
736+ _value = getattr (self , property )
737+ except KeyError :
738+ continue
739+
740+ if isinstance (_value , types .GeneratorType ):
741+ continue
742+
743+ _property_values .append (f"{ property } ={ _value !r} " )
744+
745+ _out_str += ", " .join (_property_values )
747746 _out_str += ")"
748747 return _out_str
0 commit comments