Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent type inference with type(None) #12658

Closed
smackesey opened this issue Apr 22, 2022 · 3 comments
Closed

Inconsistent type inference with type(None) #12658

smackesey opened this issue Apr 22, 2022 · 3 comments
Labels
bug mypy got something wrong

Comments

@smackesey
Copy link

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

  • Mypy version used: 0.942
  • Python version used: 3.10.4
  • Operating system and version: macOS 12.3.1
@smackesey smackesey added the bug mypy got something wrong label Apr 22, 2022
@Zeckie
Copy link

Zeckie commented Apr 24, 2022

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
Copy link
Author

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)).

@brianschubert
Copy link
Collaborator

As of #16315 (released with mypy v1.9.0), mypy infers type[None] for both cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants