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

Method trait_has_value

traitlets/traitlets.py:1836–1857  ·  view source on GitHub ↗

Returns True if the specified trait has a value. This will return false even if ``getattr`` would return a dynamically generated default value. These default values will be recognized as existing only after they have been generated. Example .. code-

(self, name: str)

Source from the content-addressed store, hash-verified

1834 return name in self._traits
1835
1836 def trait_has_value(self, name: str) -> bool:
1837 """Returns True if the specified trait has a value.
1838
1839 This will return false even if ``getattr`` would return a
1840 dynamically generated default value. These default values
1841 will be recognized as existing only after they have been
1842 generated.
1843
1844 Example
1845
1846 .. code-block:: python
1847
1848 class MyClass(HasTraits):
1849 i = Int()
1850
1851
1852 mc = MyClass()
1853 assert not mc.trait_has_value("i")
1854 mc.i # generates a default value
1855 assert mc.trait_has_value("i")
1856 """
1857 return name in self._trait_values
1858
1859 def trait_values(self, **metadata: t.Any) -> dict[str, t.Any]:
1860 """A ``dict`` of trait names and their values.

Callers 1

test_trait_has_valueMethod · 0.80

Calls

no outgoing calls

Tested by 1

test_trait_has_valueMethod · 0.64