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

Method trait_defaults

traitlets/traitlets.py:1893–1913  ·  view source on GitHub ↗

Return a trait's default value or a dictionary of them Notes ----- Dynamically generated default values may depend on the current state of the object.

(self, *names: str, **metadata: t.Any)

Source from the content-addressed store, hash-verified

1891 return self._all_trait_default_generators[name]
1892
1893 def trait_defaults(self, *names: str, **metadata: t.Any) -> dict[str, t.Any] | Sentinel:
1894 """Return a trait's default value or a dictionary of them
1895
1896 Notes
1897 -----
1898 Dynamically generated default values may
1899 depend on the current state of the object."""
1900 for n in names:
1901 if not self.has_trait(n):
1902 raise TraitError(f"'{n}' is not a trait of '{type(self).__name__}' instances")
1903
1904 if len(names) == 1 and len(metadata) == 0:
1905 return self._get_trait_default_generator(names[0])(self) # type:ignore[no-any-return]
1906
1907 trait_names = self.trait_names(**metadata)
1908 trait_names.extend(names)
1909
1910 defaults = {}
1911 for n in trait_names:
1912 defaults[n] = self._get_trait_default_generator(n)(self)
1913 return defaults
1914
1915 def trait_names(self, **metadata: t.Any) -> list[str]:
1916 """Get a list of all the names of this class' traits."""

Callers 1

getMethod · 0.80

Calls 5

has_traitMethod · 0.95
trait_namesMethod · 0.95
TraitErrorClass · 0.85
extendMethod · 0.80

Tested by

no test coverage detected