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

Function mypy_bool_typing

tests/test_typing.py:308–345  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

306
307@pytest.mark.mypy_testing
308def mypy_bool_typing() -> None:
309 class T(HasTraits):
310 b = Bool(True).tag(sync=True)
311 ob = Bool(None, allow_none=True).tag(sync=True)
312
313 t = T()
314 reveal_type(
315 Bool(True) # R: traitlets.traitlets.Bool[builtins.bool, builtins.bool | builtins.int]
316 )
317 reveal_type(
318 Bool( # R: traitlets.traitlets.Bool[builtins.bool, builtins.bool | builtins.int]
319 True
320 ).tag(sync=True)
321 )
322 reveal_type(
323 Bool( # R: traitlets.traitlets.Bool[builtins.bool | None, builtins.bool | builtins.int | None]
324 None, allow_none=True
325 )
326 )
327 reveal_type(
328 Bool( # R: traitlets.traitlets.Bool[builtins.bool | None, builtins.bool | builtins.int | None]
329 None, allow_none=True
330 ).tag(sync=True)
331 )
332 reveal_type(
333 T.b # R: traitlets.traitlets.Bool[builtins.bool, builtins.bool | builtins.int]
334 )
335 reveal_type(t.b) # R: builtins.bool
336 reveal_type(t.ob) # R: builtins.bool | None
337 reveal_type(
338 T.b # R: traitlets.traitlets.Bool[builtins.bool, builtins.bool | builtins.int]
339 )
340 reveal_type(
341 T.ob # R: traitlets.traitlets.Bool[builtins.bool | None, builtins.bool | builtins.int | None]
342 )
343 # we would expect this to be Optional[bool | int], but...
344 t.b = "foo" # E: Incompatible types in assignment (expression has type "str", variable has type "bool | int") [assignment]
345 t.b = None # E: Incompatible types in assignment (expression has type "None", variable has type "bool | int") [assignment]
346
347
348@pytest.mark.mypy_testing

Callers

nothing calls this directly

Calls 4

BoolClass · 0.90
TClass · 0.85
reveal_typeFunction · 0.85
tagMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…