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

Method traits

traitlets/traitlets.py:1919–1948  ·  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. The TraitTypes returned don't know anything about the values that the various HasTrait's instances are holding. The metadata kwargs allow f

(self, **metadata: t.Any)

Source from the content-addressed store, hash-verified

1917 return list(self.traits(**metadata))
1918
1919 def traits(self, **metadata: t.Any) -> dict[str, TraitType[t.Any, t.Any]]:
1920 """Get a ``dict`` of all the traits of this class. The dictionary
1921 is keyed on the name and the values are the TraitType objects.
1922
1923 The TraitTypes returned don't know anything about the values
1924 that the various HasTrait's instances are holding.
1925
1926 The metadata kwargs allow functions to be passed in which
1927 filter traits based on metadata values. The functions should
1928 take a single value as an argument and return a boolean. If
1929 any function returns False, then the trait is not included in
1930 the output. If a metadata key doesn't exist, None will be passed
1931 to the function.
1932 """
1933 traits = self._traits.copy()
1934
1935 if len(metadata) == 0:
1936 return traits
1937
1938 result = {}
1939 for name, trait in traits.items():
1940 for meta_name, meta_eval in metadata.items():
1941 if not callable(meta_eval):
1942 meta_eval = _SimpleTest(meta_eval)
1943 if not meta_eval(trait.metadata.get(meta_name, None)):
1944 break
1945 else:
1946 result[name] = trait
1947
1948 return result
1949
1950 def trait_metadata(self, traitname: str, key: str, default: t.Any = None) -> t.Any:
1951 """Get metadata values for trait by key."""

Callers 12

trait_namesMethod · 0.95
test_traitsMethod · 0.80
test_traits_metadataMethod · 0.80
test_allow_noneMethod · 0.80
test_klassMethod · 0.80
test_klassMethod · 0.80
test_klassMethod · 0.80
_validate_linkFunction · 0.80
test_allow_noneMethod · 0.80
_load_configMethod · 0.80
_config_changedMethod · 0.80

Calls 3

_SimpleTestClass · 0.85
copyMethod · 0.80
getMethod · 0.45

Tested by 8

test_traitsMethod · 0.64
test_traits_metadataMethod · 0.64
test_allow_noneMethod · 0.64
test_klassMethod · 0.64
test_klassMethod · 0.64
test_klassMethod · 0.64
test_allow_noneMethod · 0.64