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

Class Parity

tests/test_traitlets.py:1963–1974  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1961 """Verify that the early validation hook is effective"""
1962
1963 class Parity(HasTraits):
1964 value = Int(0)
1965 parity = Enum(["odd", "even"], default_value="even")
1966
1967 @validate("value")
1968 def _value_validate(self, proposal):
1969 value = proposal["value"]
1970 if self.parity == "even" and value % 2:
1971 raise TraitError("Expected an even number")
1972 if self.parity == "odd" and (value % 2 == 0):
1973 raise TraitError("Expected an odd number")
1974 return value
1975
1976 u = Parity()
1977 u.parity = "odd"

Callers 1

test_parity_traitMethod · 0.85

Calls 2

IntClass · 0.90
EnumClass · 0.90

Tested by 1

test_parity_traitMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…