MCPcopy Create free account
hub / github.com/ipython/traitlets / get

Method get

traitlets/traitlets.py:648–685  ·  view source on GitHub ↗
(self, obj: HasTraits, cls: type[t.Any] | None = None)

Source from the content-addressed store, hash-verified

646 return value
647
648 def get(self, obj: HasTraits, cls: type[t.Any] | None = None) -> G | None:
649 assert self.name is not None
650 try:
651 value = obj._trait_values[self.name]
652 except KeyError:
653 # Check for a dynamic initializer.
654 default = obj.trait_defaults(self.name)
655 if default is Undefined:
656 warn(
657 "Explicit using of Undefined as the default value "
658 "is deprecated in traitlets 5.0, and may cause "
659 "exceptions in the future.",
660 DeprecationWarning,
661 stacklevel=2,
662 )
663 # Using a context manager has a large runtime overhead, so we
664 # write out the obj.cross_validation_lock call here.
665 _cross_validation_lock = obj._cross_validation_lock
666 try:
667 obj._cross_validation_lock = True
668 value = self._validate(obj, default)
669 finally:
670 obj._cross_validation_lock = _cross_validation_lock
671 obj._trait_values[self.name] = value
672 obj._notify_observers(
673 Bunch(
674 name=self.name,
675 value=value,
676 owner=obj,
677 type="default",
678 )
679 )
680 return value # type:ignore[no-any-return]
681 except Exception as e:
682 # This should never be reached.
683 raise TraitError("Unexpected error in TraitType: default value not set properly") from e
684 else:
685 return value # type:ignore[no-any-return]
686
687 @t.overload
688 def __get__(self, obj: None, cls: type[t.Any]) -> Self:

Callers 15

__get__Method · 0.95
setup_instanceMethod · 0.45
__init__Method · 0.45
__init__Method · 0.45
get_metadataMethod · 0.45
setup_classMethod · 0.45
holdMethod · 0.45
_notify_observersMethod · 0.45
class_traitsMethod · 0.45
traitsMethod · 0.45
trait_metadataMethod · 0.45

Calls 6

_validateMethod · 0.95
warnFunction · 0.85
BunchClass · 0.85
TraitErrorClass · 0.85
trait_defaultsMethod · 0.80
_notify_observersMethod · 0.80

Tested by 3

setup_instanceMethod · 0.36
__init__Method · 0.36