type without arguments becomes type[nothing] instead of type[Any] #16001
Open
Description
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&gist=07773fc6948673f0c4279ecf835537cc
from typing import Any, TypeVar, assert_type
T = TypeVar("T")
def fn(x: type[T]) -> list[T]:
return []
def test(x: type) -> None:
assert_type(fn(x), list[Any])
Expected Behavior
I expect this to work. According to PEP 484: https://peps.python.org/pep-0484/#the-type-of-class-objects
Plain Type without brackets is equivalent to Type[Any] and this in turn is equivalent to type (the root of Python’s metaclass hierarchy).
Actual Behavior
main.py:9: error: Expression is of type "list[<nothing>]", not "list[Any]" [assert-type]
The type parameter for type
became nothing
instead of Any
. However, if I explicitly use type[Any]
this works as expected:
def test(x: type[Any]) -> None:
assert_type(fn(x), list[Any])
It also works if I use typing.Type
without arguments instead of type
.
Your Environment
- Mypy version used: 1.5.1
- Python version used: 3.11