rosetta_scripts¶
- pyrosetta.distributed.tasks.rosetta_scripts.validate(protocol_xml)¶
Perform schema and parse validation for the given protocol xml.
- class pyrosetta.distributed.tasks.rosetta_scripts.BaseRosettaScriptsTask(**kwargs: Any)¶
Bases:
TaskBase
- property parser¶
- protocol_xml¶
A casting version of the unicode trait.
- __init__(protocol_xml)¶
- setup()¶
- property parsed_protocol¶
- execute(pack_or_pose)¶
- _add_notifiers(handler: Callable[[...], Any], name: traitlets.utils.sentinel.Sentinel | str, type: str | traitlets.utils.sentinel.Sentinel) None ¶
- _all_trait_default_generators: dict[str, t.Any] = {'protocol_xml': <bound method TraitType.default of <traitlets.traitlets.CUnicode object>>}¶
- _descriptors = [<traitlets.traitlets.CUnicode object>]¶
- classmethod _get_logger()¶
- _get_trait_default_generator(name: str) Any ¶
Return default generator for a given trait
Walk the MRO to resolve the correct default generator according to inheritance.
- _instance_inits = []¶
- _logger = <Logger pyrosetta.distributed.tasks.rosetta_scripts.BaseRosettaScriptsTask (WARNING)>¶
- _register_validator(handler: Callable[[...], None], names: tuple[str | traitlets.utils.sentinel.Sentinel, ...]) None ¶
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.
- handlercallable
A callable that is called when the given trait is cross-validated. Its signature is handler(proposal), where proposal is a Bunch (dictionary with attribute access) with the following attributes/keys:
owner
: the HasTraits instancevalue
: the proposed value for the modified trait attributetrait
: the TraitType instance associated with the attribute
- namesList of strings
The names of the traits that should be cross-validated
- _remove_notifiers(handler: Optional[Callable[[...], Any]], name: traitlets.utils.sentinel.Sentinel | str, type: str | traitlets.utils.sentinel.Sentinel) None ¶
- _static_immutable_initial_values: dict[str, t.Any] = {'protocol_xml': ''}¶
- _trait_default_generators = {}¶
- _traits: dict[str, t.Any] = {'protocol_xml': <traitlets.traitlets.CUnicode object>}¶
- classmethod class_own_trait_events(name: str) dict[str, traitlets.traitlets.EventHandler] ¶
Get a dict of all event handlers defined on this class, not a parent.
Works like
event_handlers
, except for excluding traits from parents.
- classmethod class_own_traits(**metadata: Any) dict[str, traitlets.traitlets.TraitType[Any, Any]] ¶
Get a dict of all the traitlets defined on this class, not a parent.
Works like class_traits, except for excluding traits from parents.
- classmethod class_trait_names(**metadata: Any) list[str] ¶
Get a list of all the names of this class’ traits.
This method is just like the
trait_names()
method, but is unbound.
- classmethod class_traits(**metadata: Any) dict[str, traitlets.traitlets.TraitType[Any, Any]] ¶
Get a
dict
of all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.This method is just like the
traits()
method, but is unbound.The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- property cross_validation_lock: Any¶
A contextmanager for running a block with our cross validation lock set to True.
At the end of the block, the lock’s value is restored to its value prior to entering the block.
- has_trait(name: str) bool ¶
Returns True if the object has a trait with the specified name.
- hold_trait_notifications() Any ¶
Context manager for bundling trait change notifications and cross validation.
Use this when doing multiple trait assignments (init, config), to avoid race conditions in trait notifiers requesting other trait values. All trait notifications will fire after all values have been assigned.
- logger = <Logger pyrosetta.distributed.tasks.rosetta_scripts.BaseRosettaScriptsTask (WARNING)>¶
- maybe_setup()¶
- observe(handler: Callable[[...], Any], names: Union[Sentinel, str, Iterable[traitlets.utils.sentinel.Sentinel | str]] = traitlets.All, type: traitlets.utils.sentinel.Sentinel | str = 'change') None ¶
Setup a handler to be called when a trait changes.
This is used to setup dynamic notifications of trait changes.
- handlercallable
A callable that is called when a trait changes. Its signature should be
handler(change)
, wherechange
is a dictionary. The change dictionary at least holds a ‘type’ key. *type
: the type of notification. Other keys may be passed depending on the value of ‘type’. In the case where type is ‘change’, we also have the following keys: *owner
: the HasTraits instance *old
: the old value of the modified trait attribute *new
: the new value of the modified trait attribute *name
: the name of the modified trait attribute.- nameslist, str, All
If names is All, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.
- typestr, All (default: ‘change’)
The type of notification to filter by. If equal to All, then all notifications are passed to the observe handler.
- on_trait_change(handler: traitlets.traitlets.EventHandler | None = None, name: traitlets.utils.sentinel.Sentinel | str | None = None, remove: bool = False) None ¶
DEPRECATED: Setup a handler to be called when a trait changes.
This is used to setup dynamic notifications of trait changes.
Static handlers can be created by creating methods on a HasTraits subclass with the naming convention ‘_[traitname]_changed’. Thus, to create static handler for the trait ‘a’, create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below).
If remove is True and handler is not specified, all change handlers for the specified name are uninstalled.
- handlercallable, None
A callable that is called when a trait changes. Its signature can be handler(), handler(name), handler(name, new), handler(name, old, new), or handler(name, old, new, self).
- namelist, str, None
If None, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.
- removebool
If False (the default), then install the handler. If True then unintall it.
- set_trait(name: str, value: Any) None ¶
Forcibly sets trait attribute, including read-only attributes.
- trait_defaults(*names: str, **metadata: Any) dict[str, Any] | traitlets.utils.sentinel.Sentinel ¶
Return a trait’s default value or a dictionary of them
Dynamically generated default values may depend on the current state of the object.
- classmethod trait_events(name: str | None = None) dict[str, traitlets.traitlets.EventHandler] ¶
Get a
dict
of all the event handlers of this class.- namestr (default: None)
The name of a trait of this class. If name is
None
then all the event handlers of this class will be returned instead.
The event handlers associated with a trait name, or all event handlers.
- trait_has_value(name: str) bool ¶
Returns True if the specified trait has a value.
This will return false even if
getattr
would return a dynamically generated default value. These default values will be recognized as existing only after they have been generated.Example
class MyClass(HasTraits): i = Int() mc = MyClass() assert not mc.trait_has_value("i") mc.i # generates a default value assert mc.trait_has_value("i")
- trait_metadata(traitname: str, key: str, default: Any = None) Any ¶
Get metadata values for trait by key.
- trait_names(**metadata: Any) list[str] ¶
Get a list of all the names of this class’ traits.
- trait_values(**metadata: Any) dict[str, Any] ¶
A
dict
of trait names and their values.The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
A
dict
of trait names and their values.Trait values are retrieved via
getattr
, any exceptions raised by traits or the operations they may trigger will result in the absence of a trait value in the resultdict
.
- traits(**metadata: Any) dict[str, traitlets.traitlets.TraitType[Any, Any]] ¶
Get a
dict
of all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- unobserve(handler: Callable[[...], Any], names: Union[Sentinel, str, Iterable[traitlets.utils.sentinel.Sentinel | str]] = traitlets.All, type: traitlets.utils.sentinel.Sentinel | str = 'change') None ¶
Remove a trait change handler.
This is used to unregister handlers to trait change notifications.
- handlercallable
The callable called when a trait attribute changes.
- nameslist, str, All (default: All)
The names of the traits for which the specified handler should be uninstalled. If names is All, the specified handler is uninstalled from the list of notifiers corresponding to all changes.
- typestr or All (default: ‘change’)
The type of notification to filter by. If All, the specified handler is uninstalled from the list of notifiers corresponding to all types.
- unobserve_all(name: str | Any = traitlets.All) None ¶
Remove trait change handlers of any type for the specified name. If name is not specified, removes all trait notifiers.
- _trait_values: dict[str, t.Any]¶
- _trait_notifiers: dict[str | Sentinel, t.Any]¶
- _trait_validators: dict[str | Sentinel, t.Any]¶
- _cross_validation_lock: bool¶
- class pyrosetta.distributed.tasks.rosetta_scripts.MultioutputRosettaScriptsTask(**kwargs: Any)¶
Bases:
BaseRosettaScriptsTask
- apply(pack_or_pose)¶
Apply task generating pose objects.
- __init__(protocol_xml)¶
- _add_notifiers(handler: Callable[[...], Any], name: traitlets.utils.sentinel.Sentinel | str, type: str | traitlets.utils.sentinel.Sentinel) None ¶
- _all_trait_default_generators: dict[str, t.Any] = {'protocol_xml': <bound method TraitType.default of <traitlets.traitlets.CUnicode object>>}¶
- _descriptors = [<traitlets.traitlets.CUnicode object>]¶
- classmethod _get_logger()¶
- _get_trait_default_generator(name: str) Any ¶
Return default generator for a given trait
Walk the MRO to resolve the correct default generator according to inheritance.
- _instance_inits = []¶
- _logger = <Logger pyrosetta.distributed.tasks.rosetta_scripts.MultioutputRosettaScriptsTask (WARNING)>¶
- _register_validator(handler: Callable[[...], None], names: tuple[str | traitlets.utils.sentinel.Sentinel, ...]) None ¶
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.
- handlercallable
A callable that is called when the given trait is cross-validated. Its signature is handler(proposal), where proposal is a Bunch (dictionary with attribute access) with the following attributes/keys:
owner
: the HasTraits instancevalue
: the proposed value for the modified trait attributetrait
: the TraitType instance associated with the attribute
- namesList of strings
The names of the traits that should be cross-validated
- _remove_notifiers(handler: Optional[Callable[[...], Any]], name: traitlets.utils.sentinel.Sentinel | str, type: str | traitlets.utils.sentinel.Sentinel) None ¶
- _static_immutable_initial_values: dict[str, t.Any] = {'protocol_xml': ''}¶
- _trait_default_generators = {}¶
- _traits: dict[str, t.Any] = {'protocol_xml': <traitlets.traitlets.CUnicode object>}¶
- classmethod class_own_trait_events(name: str) dict[str, traitlets.traitlets.EventHandler] ¶
Get a dict of all event handlers defined on this class, not a parent.
Works like
event_handlers
, except for excluding traits from parents.
- classmethod class_own_traits(**metadata: Any) dict[str, traitlets.traitlets.TraitType[Any, Any]] ¶
Get a dict of all the traitlets defined on this class, not a parent.
Works like class_traits, except for excluding traits from parents.
- classmethod class_trait_names(**metadata: Any) list[str] ¶
Get a list of all the names of this class’ traits.
This method is just like the
trait_names()
method, but is unbound.
- classmethod class_traits(**metadata: Any) dict[str, traitlets.traitlets.TraitType[Any, Any]] ¶
Get a
dict
of all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.This method is just like the
traits()
method, but is unbound.The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- property cross_validation_lock: Any¶
A contextmanager for running a block with our cross validation lock set to True.
At the end of the block, the lock’s value is restored to its value prior to entering the block.
- execute(pack_or_pose)¶
- has_trait(name: str) bool ¶
Returns True if the object has a trait with the specified name.
- hold_trait_notifications() Any ¶
Context manager for bundling trait change notifications and cross validation.
Use this when doing multiple trait assignments (init, config), to avoid race conditions in trait notifiers requesting other trait values. All trait notifications will fire after all values have been assigned.
- logger = <Logger pyrosetta.distributed.tasks.rosetta_scripts.MultioutputRosettaScriptsTask (WARNING)>¶
- maybe_setup()¶
- observe(handler: Callable[[...], Any], names: Union[Sentinel, str, Iterable[traitlets.utils.sentinel.Sentinel | str]] = traitlets.All, type: traitlets.utils.sentinel.Sentinel | str = 'change') None ¶
Setup a handler to be called when a trait changes.
This is used to setup dynamic notifications of trait changes.
- handlercallable
A callable that is called when a trait changes. Its signature should be
handler(change)
, wherechange
is a dictionary. The change dictionary at least holds a ‘type’ key. *type
: the type of notification. Other keys may be passed depending on the value of ‘type’. In the case where type is ‘change’, we also have the following keys: *owner
: the HasTraits instance *old
: the old value of the modified trait attribute *new
: the new value of the modified trait attribute *name
: the name of the modified trait attribute.- nameslist, str, All
If names is All, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.
- typestr, All (default: ‘change’)
The type of notification to filter by. If equal to All, then all notifications are passed to the observe handler.
- on_trait_change(handler: traitlets.traitlets.EventHandler | None = None, name: traitlets.utils.sentinel.Sentinel | str | None = None, remove: bool = False) None ¶
DEPRECATED: Setup a handler to be called when a trait changes.
This is used to setup dynamic notifications of trait changes.
Static handlers can be created by creating methods on a HasTraits subclass with the naming convention ‘_[traitname]_changed’. Thus, to create static handler for the trait ‘a’, create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below).
If remove is True and handler is not specified, all change handlers for the specified name are uninstalled.
- handlercallable, None
A callable that is called when a trait changes. Its signature can be handler(), handler(name), handler(name, new), handler(name, old, new), or handler(name, old, new, self).
- namelist, str, None
If None, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.
- removebool
If False (the default), then install the handler. If True then unintall it.
- property parsed_protocol¶
- property parser¶
- protocol_xml¶
A casting version of the unicode trait.
- set_trait(name: str, value: Any) None ¶
Forcibly sets trait attribute, including read-only attributes.
- setup()¶
- trait_defaults(*names: str, **metadata: Any) dict[str, Any] | traitlets.utils.sentinel.Sentinel ¶
Return a trait’s default value or a dictionary of them
Dynamically generated default values may depend on the current state of the object.
- classmethod trait_events(name: str | None = None) dict[str, traitlets.traitlets.EventHandler] ¶
Get a
dict
of all the event handlers of this class.- namestr (default: None)
The name of a trait of this class. If name is
None
then all the event handlers of this class will be returned instead.
The event handlers associated with a trait name, or all event handlers.
- trait_has_value(name: str) bool ¶
Returns True if the specified trait has a value.
This will return false even if
getattr
would return a dynamically generated default value. These default values will be recognized as existing only after they have been generated.Example
class MyClass(HasTraits): i = Int() mc = MyClass() assert not mc.trait_has_value("i") mc.i # generates a default value assert mc.trait_has_value("i")
- trait_metadata(traitname: str, key: str, default: Any = None) Any ¶
Get metadata values for trait by key.
- trait_names(**metadata: Any) list[str] ¶
Get a list of all the names of this class’ traits.
- trait_values(**metadata: Any) dict[str, Any] ¶
A
dict
of trait names and their values.The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
A
dict
of trait names and their values.Trait values are retrieved via
getattr
, any exceptions raised by traits or the operations they may trigger will result in the absence of a trait value in the resultdict
.
- traits(**metadata: Any) dict[str, traitlets.traitlets.TraitType[Any, Any]] ¶
Get a
dict
of all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- unobserve(handler: Callable[[...], Any], names: Union[Sentinel, str, Iterable[traitlets.utils.sentinel.Sentinel | str]] = traitlets.All, type: traitlets.utils.sentinel.Sentinel | str = 'change') None ¶
Remove a trait change handler.
This is used to unregister handlers to trait change notifications.
- handlercallable
The callable called when a trait attribute changes.
- nameslist, str, All (default: All)
The names of the traits for which the specified handler should be uninstalled. If names is All, the specified handler is uninstalled from the list of notifiers corresponding to all changes.
- typestr or All (default: ‘change’)
The type of notification to filter by. If All, the specified handler is uninstalled from the list of notifiers corresponding to all types.
- unobserve_all(name: str | Any = traitlets.All) None ¶
Remove trait change handlers of any type for the specified name. If name is not specified, removes all trait notifiers.
- _trait_values: dict[str, t.Any]¶
- _trait_notifiers: dict[str | Sentinel, t.Any]¶
- _trait_validators: dict[str | Sentinel, t.Any]¶
- _cross_validation_lock: bool¶
- class pyrosetta.distributed.tasks.rosetta_scripts.SingleoutputRosettaScriptsTask(**kwargs: Any)¶
Bases:
BaseRosettaScriptsTask
- apply(pack_or_pose)¶
Apply task returning a pose object.
- __init__(protocol_xml)¶
- _add_notifiers(handler: Callable[[...], Any], name: traitlets.utils.sentinel.Sentinel | str, type: str | traitlets.utils.sentinel.Sentinel) None ¶
- _all_trait_default_generators: dict[str, t.Any] = {'protocol_xml': <bound method TraitType.default of <traitlets.traitlets.CUnicode object>>}¶
- _descriptors = [<traitlets.traitlets.CUnicode object>]¶
- classmethod _get_logger()¶
- _get_trait_default_generator(name: str) Any ¶
Return default generator for a given trait
Walk the MRO to resolve the correct default generator according to inheritance.
- _instance_inits = []¶
- _logger = <Logger pyrosetta.distributed.tasks.rosetta_scripts.SingleoutputRosettaScriptsTask (WARNING)>¶
- _register_validator(handler: Callable[[...], None], names: tuple[str | traitlets.utils.sentinel.Sentinel, ...]) None ¶
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.
- handlercallable
A callable that is called when the given trait is cross-validated. Its signature is handler(proposal), where proposal is a Bunch (dictionary with attribute access) with the following attributes/keys:
owner
: the HasTraits instancevalue
: the proposed value for the modified trait attributetrait
: the TraitType instance associated with the attribute
- namesList of strings
The names of the traits that should be cross-validated
- _remove_notifiers(handler: Optional[Callable[[...], Any]], name: traitlets.utils.sentinel.Sentinel | str, type: str | traitlets.utils.sentinel.Sentinel) None ¶
- _static_immutable_initial_values: dict[str, t.Any] = {'protocol_xml': ''}¶
- _trait_default_generators = {}¶
- _traits: dict[str, t.Any] = {'protocol_xml': <traitlets.traitlets.CUnicode object>}¶
- classmethod class_own_trait_events(name: str) dict[str, traitlets.traitlets.EventHandler] ¶
Get a dict of all event handlers defined on this class, not a parent.
Works like
event_handlers
, except for excluding traits from parents.
- classmethod class_own_traits(**metadata: Any) dict[str, traitlets.traitlets.TraitType[Any, Any]] ¶
Get a dict of all the traitlets defined on this class, not a parent.
Works like class_traits, except for excluding traits from parents.
- classmethod class_trait_names(**metadata: Any) list[str] ¶
Get a list of all the names of this class’ traits.
This method is just like the
trait_names()
method, but is unbound.
- classmethod class_traits(**metadata: Any) dict[str, traitlets.traitlets.TraitType[Any, Any]] ¶
Get a
dict
of all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.This method is just like the
traits()
method, but is unbound.The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- property cross_validation_lock: Any¶
A contextmanager for running a block with our cross validation lock set to True.
At the end of the block, the lock’s value is restored to its value prior to entering the block.
- execute(pack_or_pose)¶
- has_trait(name: str) bool ¶
Returns True if the object has a trait with the specified name.
- hold_trait_notifications() Any ¶
Context manager for bundling trait change notifications and cross validation.
Use this when doing multiple trait assignments (init, config), to avoid race conditions in trait notifiers requesting other trait values. All trait notifications will fire after all values have been assigned.
- logger = <Logger pyrosetta.distributed.tasks.rosetta_scripts.SingleoutputRosettaScriptsTask (WARNING)>¶
- maybe_setup()¶
- observe(handler: Callable[[...], Any], names: Union[Sentinel, str, Iterable[traitlets.utils.sentinel.Sentinel | str]] = traitlets.All, type: traitlets.utils.sentinel.Sentinel | str = 'change') None ¶
Setup a handler to be called when a trait changes.
This is used to setup dynamic notifications of trait changes.
- handlercallable
A callable that is called when a trait changes. Its signature should be
handler(change)
, wherechange
is a dictionary. The change dictionary at least holds a ‘type’ key. *type
: the type of notification. Other keys may be passed depending on the value of ‘type’. In the case where type is ‘change’, we also have the following keys: *owner
: the HasTraits instance *old
: the old value of the modified trait attribute *new
: the new value of the modified trait attribute *name
: the name of the modified trait attribute.- nameslist, str, All
If names is All, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.
- typestr, All (default: ‘change’)
The type of notification to filter by. If equal to All, then all notifications are passed to the observe handler.
- on_trait_change(handler: traitlets.traitlets.EventHandler | None = None, name: traitlets.utils.sentinel.Sentinel | str | None = None, remove: bool = False) None ¶
DEPRECATED: Setup a handler to be called when a trait changes.
This is used to setup dynamic notifications of trait changes.
Static handlers can be created by creating methods on a HasTraits subclass with the naming convention ‘_[traitname]_changed’. Thus, to create static handler for the trait ‘a’, create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below).
If remove is True and handler is not specified, all change handlers for the specified name are uninstalled.
- handlercallable, None
A callable that is called when a trait changes. Its signature can be handler(), handler(name), handler(name, new), handler(name, old, new), or handler(name, old, new, self).
- namelist, str, None
If None, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.
- removebool
If False (the default), then install the handler. If True then unintall it.
- property parsed_protocol¶
- property parser¶
- protocol_xml¶
A casting version of the unicode trait.
- set_trait(name: str, value: Any) None ¶
Forcibly sets trait attribute, including read-only attributes.
- setup()¶
- trait_defaults(*names: str, **metadata: Any) dict[str, Any] | traitlets.utils.sentinel.Sentinel ¶
Return a trait’s default value or a dictionary of them
Dynamically generated default values may depend on the current state of the object.
- classmethod trait_events(name: str | None = None) dict[str, traitlets.traitlets.EventHandler] ¶
Get a
dict
of all the event handlers of this class.- namestr (default: None)
The name of a trait of this class. If name is
None
then all the event handlers of this class will be returned instead.
The event handlers associated with a trait name, or all event handlers.
- trait_has_value(name: str) bool ¶
Returns True if the specified trait has a value.
This will return false even if
getattr
would return a dynamically generated default value. These default values will be recognized as existing only after they have been generated.Example
class MyClass(HasTraits): i = Int() mc = MyClass() assert not mc.trait_has_value("i") mc.i # generates a default value assert mc.trait_has_value("i")
- trait_metadata(traitname: str, key: str, default: Any = None) Any ¶
Get metadata values for trait by key.
- trait_names(**metadata: Any) list[str] ¶
Get a list of all the names of this class’ traits.
- trait_values(**metadata: Any) dict[str, Any] ¶
A
dict
of trait names and their values.The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
A
dict
of trait names and their values.Trait values are retrieved via
getattr
, any exceptions raised by traits or the operations they may trigger will result in the absence of a trait value in the resultdict
.
- traits(**metadata: Any) dict[str, traitlets.traitlets.TraitType[Any, Any]] ¶
Get a
dict
of all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- unobserve(handler: Callable[[...], Any], names: Union[Sentinel, str, Iterable[traitlets.utils.sentinel.Sentinel | str]] = traitlets.All, type: traitlets.utils.sentinel.Sentinel | str = 'change') None ¶
Remove a trait change handler.
This is used to unregister handlers to trait change notifications.
- handlercallable
The callable called when a trait attribute changes.
- nameslist, str, All (default: All)
The names of the traits for which the specified handler should be uninstalled. If names is All, the specified handler is uninstalled from the list of notifiers corresponding to all changes.
- typestr or All (default: ‘change’)
The type of notification to filter by. If All, the specified handler is uninstalled from the list of notifiers corresponding to all types.
- unobserve_all(name: str | Any = traitlets.All) None ¶
Remove trait change handlers of any type for the specified name. If name is not specified, removes all trait notifiers.
- _trait_values: dict[str, t.Any]¶
- _trait_notifiers: dict[str | Sentinel, t.Any]¶
- _trait_validators: dict[str | Sentinel, t.Any]¶
- _cross_validation_lock: bool¶