Skip to content

No narrowing on type(...) is T #2530

@superbobry

Description

@superbobry

Describe the Bug

Reproducer:

from typing import reveal_type

def f(x: int | bool):  # does not narrow
  if type(x) is bool:
    x = 42
  reveal_type(x)


def g(x: int | None):  # works OK
  if x is None:
    x = 42
  reveal_type(x)

Output:

 INFO revealed type: bool | int [reveal-type]
 --> /tmp/foo.py:6:14
  |
6 |   reveal_type(x)
  |              ---
  |
 INFO revealed type: int [reveal-type]
  --> /tmp/foo.py:12:14
   |
12 |   reveal_type(x)
   |              ---
   |
 INFO 0 errors

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions