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

Class Float

traitlets/traitlets.py:2718–2781  ·  view source on GitHub ↗

A float trait.

Source from the content-addressed store, hash-verified

2716
2717
2718class Float(TraitType[G, S]):
2719 """A float trait."""
2720
2721 default_value = 0.0
2722 info_text = "a float"
2723
2724 @t.overload
2725 def __init__(
2726 self: Float[float, int | float],
2727 default_value: float | Sentinel = ...,
2728 allow_none: Literal[False] = ...,
2729 read_only: bool | None = ...,
2730 help: str | None = ...,
2731 config: t.Any | None = ...,
2732 **kwargs: t.Any,
2733 ) -> None:
2734 ...
2735
2736 @t.overload
2737 def __init__(
2738 self: Float[int | None, int | float | None],
2739 default_value: float | Sentinel | None = ...,
2740 allow_none: Literal[True] = ...,
2741 read_only: bool | None = ...,
2742 help: str | None = ...,
2743 config: t.Any | None = ...,
2744 **kwargs: t.Any,
2745 ) -> None:
2746 ...
2747
2748 def __init__(
2749 self: Float[int | None, int | float | None],
2750 default_value: float | Sentinel | None = Undefined,
2751 allow_none: bool = False,
2752 read_only: bool | None = False,
2753 help: str | None = None,
2754 config: t.Any | None = None,
2755 **kwargs: t.Any,
2756 ) -> None:
2757 self.min = kwargs.pop("min", -float("inf"))
2758 self.max = kwargs.pop("max", float("inf"))
2759 super().__init__(
2760 default_value=default_value,
2761 allow_none=allow_none,
2762 read_only=read_only,
2763 help=help,
2764 config=config,
2765 **kwargs,
2766 )
2767
2768 def validate(self, obj: t.Any, value: t.Any) -> G:
2769 if isinstance(value, int):
2770 value = float(value)
2771 if not isinstance(value, float):
2772 self.error(obj, value)
2773 return _validate_bounds(self, obj, value) # type:ignore[no-any-return]
2774
2775 def from_string(self, s: str) -> G:

Callers 10

AClass · 0.90
BClass · 0.90
AClass · 0.90
BClass · 0.90
AClass · 0.90
FloatTraitClass · 0.90
test_notify_allMethod · 0.90
MyConfigurableClass · 0.90
BarClass · 0.90

Calls

no outgoing calls

Tested by 2

test_notify_allMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…