()
| 306 | |
| 307 | @pytest.mark.mypy_testing |
| 308 | def 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…