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

Class Bool

traitlets/traitlets.py:3066–3138  ·  view source on GitHub ↗

A boolean (True, False) trait.

Source from the content-addressed store, hash-verified

3064
3065
3066class Bool(TraitType[G, S]):
3067 """A boolean (True, False) trait."""
3068
3069 default_value = False
3070 info_text = "a boolean"
3071
3072 if t.TYPE_CHECKING:
3073
3074 @t.overload
3075 def __init__(
3076 self: Bool[bool, bool | int],
3077 default_value: bool | Sentinel = ...,
3078 allow_none: Literal[False] = ...,
3079 read_only: bool | None = ...,
3080 help: str | None = ...,
3081 config: t.Any = ...,
3082 **kwargs: t.Any,
3083 ) -> None:
3084 ...
3085
3086 @t.overload
3087 def __init__(
3088 self: Bool[bool | None, bool | int | None],
3089 default_value: bool | Sentinel | None = ...,
3090 allow_none: Literal[True] = ...,
3091 read_only: bool | None = ...,
3092 help: str | None = ...,
3093 config: t.Any = ...,
3094 **kwargs: t.Any,
3095 ) -> None:
3096 ...
3097
3098 def __init__(
3099 self: Bool[bool | None, bool | int | None],
3100 default_value: bool | Sentinel | None = ...,
3101 allow_none: bool = ...,
3102 read_only: bool | None = ...,
3103 help: str | None = ...,
3104 config: t.Any = ...,
3105 **kwargs: t.Any,
3106 ) -> None:
3107 ...
3108
3109 def validate(self, obj: t.Any, value: t.Any) -> G:
3110 if isinstance(value, bool):
3111 return value # type:ignore[return-value]
3112 elif isinstance(value, int):
3113 if value == 1:
3114 return True # type:ignore[return-value]
3115 elif value == 0:
3116 return False # type:ignore[return-value]
3117 self.error(obj, value)
3118
3119 def from_string(self, s: str) -> G:
3120 if self.allow_none and s == "None":
3121 return None # type:ignore[return-value]
3122 s = s.lower()
3123 if s in {"true", "1"}:

Callers 15

UnionTraitClass · 0.90
OrTraitClass · 0.90
UnionListTraitClass · 0.90
TClass · 0.90
mypy_bool_typingFunction · 0.90
BarClass · 0.90
MyAppClass · 0.90
TestAppClass · 0.90
Sub3Class · 0.90
ApplicationClass · 0.90
EnvironPrinterClass · 0.90
BarClass · 0.90

Calls

no outgoing calls

Tested by 1

mypy_bool_typingFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…