ju.traitlets_util

Utils for traitlets

Functions

extract_type_params(trait_type, trait)

Extract type parameters for a trait.

trait_to_py(trait)

Convert a traitlets trait (instance or type) to a Python object (instance or type)

ju.traitlets_util.extract_type_params(trait_type, trait)[source]

Extract type parameters for a trait.

>>> extract_type_params(
...     traitlets.Union, traitlets.Union([traitlets.Unicode(), traitlets.Float()])
... )
(<class 'str'>, <class 'float'>)
ju.traitlets_util.trait_to_py(trait)[source]

Convert a traitlets trait (instance or type) to a Python object (instance or type)

Return type:

object | type

>>> trait_to_py(traitlets.Bool())
<class 'bool'>
>>> trait_to_py(traitlets.Union([traitlets.Unicode(), traitlets.Float()]))
typing.Union[str, float]