mypy icon indicating copy to clipboard operation
mypy copied to clipboard

`Value of type "Type[type]" is not indexable` error inside `reveal_type(type[type])`

Open denballakh opened this issue 3 years ago • 2 comments

When type[type] is used inside reveal_type() i get Value of type "Type[type]" is not indexable error:

reveal_type(type[type]) # Value of type "Type[type]" is not indexable
                        # Revealed type is "Any"

Expected Behavior I expect behavior similar to this example:

X: type[type[type]]
reveal_type(X) # Revealed type is "Type[Type[builtins.type]]"

So i expect this:

reveal_type(type[type]) # Revealed type is "Type[Type[builtins.type]]"

My Environment

  • mypy 0.961 (compiled: no)
  • no command-line flags, no config file
  • CPython 3.10.4
  • Windows 10

denballakh avatar Jun 26 '22 09:06 denballakh

It's the same bug as this: #12392 (I guess this isn't, strictly speaking, a duplicate, however). The underlying issue is that mypy still struggles with type[T] being used in runtime contexts.

AlexWaygood avatar Jun 26 '22 09:06 AlexWaygood

Also this:

type[int](1)  # error: Value of type "Type[type]" is not indexable

KotlinIsland avatar Sep 17 '22 04:09 KotlinIsland

Also this:

a: object = type[int]

KotlinIsland avatar Aug 17 '23 05:08 KotlinIsland