MCPcopy Create free account
hub / github.com/ipython/traitlets / class_traits

Method class_traits

traitlets/traitlets.py:1784–1815  ·  view source on GitHub ↗

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 :meth:`traits` method, but is unbound. The TraitTypes returned don't know anything about the values that the v

(cls: type[HasTraits], **metadata: t.Any)

Source from the content-addressed store, hash-verified

1782
1783 @classmethod
1784 def class_traits(cls: type[HasTraits], **metadata: t.Any) -> dict[str, TraitType[t.Any, t.Any]]:
1785 """Get a ``dict`` of all the traits of this class. The dictionary
1786 is keyed on the name and the values are the TraitType objects.
1787
1788 This method is just like the :meth:`traits` method, but is unbound.
1789
1790 The TraitTypes returned don't know anything about the values
1791 that the various HasTrait's instances are holding.
1792
1793 The metadata kwargs allow functions to be passed in which
1794 filter traits based on metadata values. The functions should
1795 take a single value as an argument and return a boolean. If
1796 any function returns False, then the trait is not included in
1797 the output. If a metadata key doesn't exist, None will be passed
1798 to the function.
1799 """
1800 traits = cls._traits.copy()
1801
1802 if len(metadata) == 0:
1803 return traits
1804
1805 result = {}
1806 for name, trait in traits.items():
1807 for meta_name, meta_eval in metadata.items():
1808 if not callable(meta_eval):
1809 meta_eval = _SimpleTest(meta_eval)
1810 if not meta_eval(trait.metadata.get(meta_name, None)):
1811 break
1812 else:
1813 result[name] = trait
1814
1815 return result
1816
1817 @classmethod
1818 def class_own_traits(

Callers 11

test_traitsMethod · 0.80
class_trait_namesMethod · 0.80
class_own_traitsMethod · 0.80
signature_has_traitsFunction · 0.80
class_get_helpMethod · 0.80
class_config_sectionMethod · 0.80
class_config_rst_docMethod · 0.80
emit_alias_helpMethod · 0.80
_add_argumentsMethod · 0.80
class_config_rst_docFunction · 0.80

Calls 3

_SimpleTestClass · 0.85
copyMethod · 0.80
getMethod · 0.45

Tested by 1

test_traitsMethod · 0.64