python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.26k stars 2.79k forks source link

Inconsistent type inference with `type(None)` #12658

Open smackesey opened 2 years ago

smackesey commented 2 years ago

Bug Report

TYPE_NONE = type(None)
reveal_type(type(None))  # => `Type[None]`
reveal_type(TYPE_NONE)  # => `builtins.object`

Expected Behavior

The two reveal_type calls above should print the same thing (Type[None])

Your Environment

Zeckie commented 2 years ago

Is that different from this (ie. reveal_type giving a narrow type for something it recognises)?

one = 1
reveal_type(1)  # note: Revealed type is 'Literal[1]?'
reveal_type(one)  # note: Revealed type is 'builtins.int'
smackesey commented 2 years ago

Not sure-- probably share a similar root but IMO the example I posted is even less intuitive (one is a Type, the other is builtins.object) because this pattern does not occur when you use a different type (like int in place of type(None)).