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)
| 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.""" |
no test coverage detected