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

Method set

traitlets/traitlets.py:708–725  ·  view source on GitHub ↗
(self, obj: HasTraits, value: S)

Source from the content-addressed store, hash-verified

706 return self.get(obj, cls) # type:ignore[return-value]
707
708 def set(self, obj: HasTraits, value: S) -> None:
709 new_value = self._validate(obj, value)
710 assert self.name is not None
711 try:
712 old_value = obj._trait_values[self.name]
713 except KeyError:
714 old_value = self.default_value
715
716 obj._trait_values[self.name] = new_value
717 try:
718 silent = bool(old_value == new_value)
719 except Exception:
720 # if there is an error in comparing, default to notify
721 silent = False
722 if silent is not True:
723 # we explicitly compare silent to True just in case the equality
724 # comparison above returns something other than True/False
725 obj._notify_trait(self.name, old_value, new_value)
726
727 def __set__(self, obj: HasTraits, value: S) -> None:
728 """Set the value of the trait by self.name for the instance.

Callers 1

__set__Method · 0.95

Calls 2

_validateMethod · 0.95
_notify_traitMethod · 0.80

Tested by

no test coverage detected