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

Inconsistency in reveal_type(some_type) #13062

Open
denballakh opened this issue Jul 3, 2022 · 1 comment
Open

Inconsistency in reveal_type(some_type) #13062

denballakh opened this issue Jul 3, 2022 · 1 comment
Labels
bug mypy got something wrong topic-reveal-type reveal_type() and reveal_locals() topic-usability

Comments

@denballakh
Copy link
Contributor

Consider this example:

t1 = int
t2: type[int] = t1

reveal_type(int) # huge overload
reveal_type(t1) # huge overload
reveal_type(t2) # Type[builtins.int]

I expect get the same result in all three reveal_type's, but in two cases i get huge overload: Overload(def (Union[builtins.str, builtins.bytes, array.array[Any], mmap.mmap, ctypes._CData, pickle.PickleBuffer, typing.SupportsInt, typing_extensions.SupportsIndex, _typeshed.SupportsTrunc] =) -> builtins.int, def (Union[builtins.str, builtins.bytes], base: typing_extensions.SupportsIndex) -> builtins.int), and in one case i get Type[builtins.int]

My Environment

  • mypy 0.961 (compiled: no)
  • no command-line flags, no config file
  • CPython 3.10.4
  • Windows 10
@denballakh denballakh added the bug mypy got something wrong label Jul 3, 2022
@AlexWaygood AlexWaygood added topic-usability topic-reveal-type reveal_type() and reveal_locals() labels Jul 3, 2022
@JukkaL
Copy link
Collaborator

JukkaL commented Apr 23, 2023

The reason for the overload is that in the first instances type object references have the type Overloaded with is_type_object() true, while for t2 the type is TypeType. These types don't behave exactly the same, so displaying the exact same type wouldn't be perfect either. The current behavior is not very good either, since we lose information that the type refers to a type object specifically, not just any callable. I'm not sure what's the best option here -- one option would be to use type[Overload(...)] instead of just Overload(...), but that could be confusing as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-reveal-type reveal_type() and reveal_locals() topic-usability
Projects
None yet
Development

No branches or pull requests

3 participants