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

Function _validate_bounds

traitlets/traitlets.py:2566–2587  ·  view source on GitHub ↗

Validate that a number to be applied to a trait is between bounds. If value is not between min_bound and max_bound, this raises a TraitError with an error message appropriate for this trait.

(
    trait: Int[t.Any, t.Any] | Float[t.Any, t.Any], obj: t.Any, value: t.Any
)

Source from the content-addressed store, hash-verified

2564
2565
2566def _validate_bounds(
2567 trait: Int[t.Any, t.Any] | Float[t.Any, t.Any], obj: t.Any, value: t.Any
2568) -> t.Any:
2569 """
2570 Validate that a number to be applied to a trait is between bounds.
2571
2572 If value is not between min_bound and max_bound, this raises a
2573 TraitError with an error message appropriate for this trait.
2574 """
2575 if trait.min is not None and value < trait.min:
2576 raise TraitError(
2577 f"The value of the '{trait.name}' trait of {class_of(obj)} instance should "
2578 f"not be less than {trait.min}, but a value of {value} was "
2579 "specified"
2580 )
2581 if trait.max is not None and value > trait.max:
2582 raise TraitError(
2583 f"The value of the '{trait.name}' trait of {class_of(obj)} instance should "
2584 f"not be greater than {trait.max}, but a value of {value} was "
2585 "specified"
2586 )
2587 return value
2588
2589
2590# I = t.TypeVar('I', t.Optional[int], int)

Callers 4

validateMethod · 0.85
validateMethod · 0.85
validateMethod · 0.85
validateMethod · 0.85

Calls 2

TraitErrorClass · 0.85
class_ofFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…