Show More
@@ -530,27 +530,33 b' class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)):' | |||||
530 |
|
530 | |||
531 | @classmethod |
|
531 | @classmethod | |
532 | def class_trait_names(cls, **metadata): |
|
532 | def class_trait_names(cls, **metadata): | |
533 |
"""Get a list of all the names of this class |
|
533 | """Get a list of all the names of this class' traits. | |
534 |
|
534 | |||
535 |
This method is just like the :meth:`trait_names` method, |
|
535 | This method is just like the :meth:`trait_names` method, | |
|
536 | but is unbound. | |||
536 | """ |
|
537 | """ | |
537 | return cls.class_traits(**metadata).keys() |
|
538 | return cls.class_traits(**metadata).keys() | |
538 |
|
539 | |||
539 | @classmethod |
|
540 | @classmethod | |
540 | def class_traits(cls, **metadata): |
|
541 | def class_traits(cls, **metadata): | |
541 |
"""Get a |
|
542 | """Get a `dict` of all the traits of this class. The dictionary | |
|
543 | is keyed on the name and the values are the TraitType objects. | |||
542 |
|
544 | |||
543 | This method is just like the :meth:`traits` method, but is unbound. |
|
545 | This method is just like the :meth:`traits` method, but is unbound. | |
544 |
|
546 | |||
545 | The TraitTypes returned don't know anything about the values |
|
547 | The TraitTypes returned don't know anything about the values | |
546 | that the various HasTrait's instances are holding. |
|
548 | that the various HasTrait's instances are holding. | |
547 |
|
549 | |||
548 | This follows the same algorithm as traits does and does not allow |
|
550 | The metadata kwargs allow functions to be passed in which | |
549 | for any simple way of specifying merely that a metadata name |
|
551 | filter traits based on metadata values. The functions should | |
550 | exists, but has any value. This is because get_metadata returns |
|
552 | take a single value as an argument and return a boolean. If | |
551 | None if a metadata key doesn't exist. |
|
553 | any function returns False, then the trait is not included in | |
|
554 | the output. This does not allow for any simple way of | |||
|
555 | testing that a metadata name exists and has any | |||
|
556 | value because get_metadata returns None if a metadata key | |||
|
557 | doesn't exist. | |||
552 | """ |
|
558 | """ | |
553 |
traits = dict([memb for memb in getmembers(cls) if |
|
559 | traits = dict([memb for memb in getmembers(cls) if | |
554 | isinstance(memb[1], TraitType)]) |
|
560 | isinstance(memb[1], TraitType)]) | |
555 |
|
561 | |||
556 | if len(metadata) == 0: |
|
562 | if len(metadata) == 0: | |
@@ -571,21 +577,26 b' class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)):' | |||||
571 | return result |
|
577 | return result | |
572 |
|
578 | |||
573 | def trait_names(self, **metadata): |
|
579 | def trait_names(self, **metadata): | |
574 |
"""Get a list of all the names of this class |
|
580 | """Get a list of all the names of this class' traits.""" | |
575 | return self.traits(**metadata).keys() |
|
581 | return self.traits(**metadata).keys() | |
576 |
|
582 | |||
577 | def traits(self, **metadata): |
|
583 | def traits(self, **metadata): | |
578 |
"""Get a |
|
584 | """Get a `dict` of all the traits of this class. The dictionary | |
|
585 | is keyed on the name and the values are the TraitType objects. | |||
579 |
|
586 | |||
580 | The TraitTypes returned don't know anything about the values |
|
587 | The TraitTypes returned don't know anything about the values | |
581 | that the various HasTrait's instances are holding. |
|
588 | that the various HasTrait's instances are holding. | |
582 |
|
589 | |||
583 | This follows the same algorithm as traits does and does not allow |
|
590 | The metadata kwargs allow functions to be passed in which | |
584 | for any simple way of specifying merely that a metadata name |
|
591 | filter traits based on metadata values. The functions should | |
585 | exists, but has any value. This is because get_metadata returns |
|
592 | take a single value as an argument and return a boolean. If | |
586 | None if a metadata key doesn't exist. |
|
593 | any function returns False, then the trait is not included in | |
|
594 | the output. This does not allow for any simple way of | |||
|
595 | testing that a metadata name exists and has any | |||
|
596 | value because get_metadata returns None if a metadata key | |||
|
597 | doesn't exist. | |||
587 | """ |
|
598 | """ | |
588 |
traits = dict([memb for memb in getmembers(self.__class__) if |
|
599 | traits = dict([memb for memb in getmembers(self.__class__) if | |
589 | isinstance(memb[1], TraitType)]) |
|
600 | isinstance(memb[1], TraitType)]) | |
590 |
|
601 | |||
591 | if len(metadata) == 0: |
|
602 | if len(metadata) == 0: |
General Comments 0
You need to be logged in to leave comments.
Login now