Source code for jupyter_starters.trait_types

"""Some more traits.

these are not typechecked yet, because of the impedance between
traitlets, JSON Schema, and mypy.
"""

# pylint: disable=broad-except,unused-argument
import traitlets

from .json_ import JsonSchemaException


[docs]class Schema(traitlets.Any): """any... but validated by a :func:`jupyter_starters.json_.json_validator` """ _validator = None
[docs] def __init__(self, validator, *args, **kwargs): super().__init__(*args, **kwargs) self._validator = validator
[docs] def validate(self, obj, value): """Applies a validator.""" try: self._validator(value) except JsonSchemaException as err: # pragma: no cover raise traitlets.TraitError(f"""schema errors: {err}""") return value