traits.trait_set_object
Module¶
Classes¶
-
class
traits.trait_set_object.
TraitSetEvent
(*, removed=None, added=None)[source]¶ An object reporting in-place changes to a traits sets.
- Parameters
-
class
traits.trait_set_object.
TraitSet
(*args, **kwargs)[source]¶ A subclass of set that validates and notifies listeners of changes.
- Parameters
value (iterable, optional) – Iterable providing the items for the set.
item_validator (callable, optional) – Called to validate and/or transform items added to the set. The callable should accept a single item and return the transformed item, raising TraitError for invalid items. If not given, no item validation is performed.
notifiers (list of callable, optional) –
A list of callables with the signature:
notifier(trait_set, removed, added)
Where ‘added’ is a set containing new values that have been added. And ‘removed’ is a set containing old values that have been removed.
If this argument is not given, the list of notifiers is initially empty.
-
item_validator
¶ Called to validate and/or transform items added to the set. The callable should accept a single item and return the transformed item, raising TraitError for invalid items.
- Type
callable
-
notifiers
¶ A list of callables with the signature:
notifier(trait_set, removed, added)
where ‘added’ is a set containing new values that have been added and ‘removed’ is a set containing old values that have been removed.
- Type
list of callable
-
notify
(removed, added)[source]¶ Call all notifiers.
This simply calls all notifiers provided by the class, if any. The notifiers are expected to have the signature:
notifier(trait_set, removed, added)
Any return values are ignored. Any exceptions raised are not handled. Notifiers are therefore expected not to raise any exceptions under normal use.
-
add
(value)[source]¶ Add an element to a set.
This has no effect if the element is already present.
- Parameters
value (any) – The value to add to the set.
-
discard
(value)[source]¶ Remove an element from the set if it is a member.
If the element is not a member, do nothing.
- Parameters
value (any) – An item in the set
-
difference_update
(*args)[source]¶ Remove all elements of another set from this set.
- Parameters
args (iterables) – The other iterables.
-
intersection_update
(*args)[source]¶ Update the set with the intersection of itself and another set.
- Parameters
args (iterables) – The other iterables.
-
pop
()[source]¶ Remove and return an arbitrary set element.
Raises KeyError if the set is empty.
- Returns
item – An element from the set.
- Return type
any
- Raises
KeyError – If the set is empty.
-
remove
(value)[source]¶ Remove an element that is a member of the set.
If the element is not a member, raise a KeyError.
- Parameters
value (any) – An element in the set
- Raises
KeyError – If the value is not found in the set.
-
class
traits.trait_set_object.
TraitSetObject
(*args, **kwargs)[source]¶ A specialization of TraitSet with a default validator and notifier for compatibility with Traits versions before 6.0.
- Parameters
trait (CTrait) – The trait that the set has been assigned to.
object (HasTraits) – The object this set belongs to. Can also be None in cases where the set has been disconnected from its HasTraits parent.
name (str) – The name of the trait on the object.
value (iterable) – The initial value of the set.
-
object
¶ A callable that when called with no arguments returns the HasTraits object that this set belongs to, or None if there is no such object.
- Type
callable
-
value
¶ The initial value of the set.
- Type
iterable