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

Method _register_validator

traitlets/traitlets.py:1719–1753  ·  view source on GitHub ↗

Setup a handler to be called when a trait should be cross validated. This is used to setup dynamic notifications for cross-validation. If a validator is already registered for any of the provided names, a TraitError is raised and no new validator is registered. Par

(
        self, handler: t.Callable[..., None], names: tuple[str | Sentinel, ...]
    )

Source from the content-addressed store, hash-verified

1717 pass
1718
1719 def _register_validator(
1720 self, handler: t.Callable[..., None], names: tuple[str | Sentinel, ...]
1721 ) -> None:
1722 """Setup a handler to be called when a trait should be cross validated.
1723
1724 This is used to setup dynamic notifications for cross-validation.
1725
1726 If a validator is already registered for any of the provided names, a
1727 TraitError is raised and no new validator is registered.
1728
1729 Parameters
1730 ----------
1731 handler : callable
1732 A callable that is called when the given trait is cross-validated.
1733 Its signature is handler(proposal), where proposal is a Bunch (dictionary with attribute access)
1734 with the following attributes/keys:
1735 * ``owner`` : the HasTraits instance
1736 * ``value`` : the proposed value for the modified trait attribute
1737 * ``trait`` : the TraitType instance associated with the attribute
1738 names : List of strings
1739 The names of the traits that should be cross-validated
1740 """
1741 for name in names:
1742 magic_name = "_%s_validate" % name
1743 if hasattr(self, magic_name):
1744 class_value = getattr(self.__class__, magic_name)
1745 if not isinstance(class_value, ValidateHandler):
1746 deprecated_method(
1747 class_value,
1748 self.__class__,
1749 magic_name,
1750 "use @validate decorator instead.",
1751 )
1752 for name in names:
1753 self._trait_validators[name] = handler
1754
1755 def add_traits(self, **traits: t.Any) -> None:
1756 """Dynamically add trait attributes to the HasTraits instance."""

Callers 1

instance_initMethod · 0.80

Calls 1

deprecated_methodFunction · 0.85

Tested by

no test coverage detected