Bug Report
mypy reveals a certain nested default generic type in type as Any, while other type checkers reveal it as the default type.
This issue is motivated by pandas-dev/pandas-stubs#1764.
To Reproduce
This is complicated, see #21608 (comment) for a much simplified example.
from typing import Any, Generic, TypeVar, reveal_type
_ItemT_co = TypeVar("_ItemT_co", default=Any, covariant=True)
class generic(Generic[_ItemT_co]): ...
_ScalarT_co = TypeVar("_ScalarT_co", bound=generic, default=Any, covariant=True)
class dtype(Generic[_ScalarT_co]): ...
_DT64ItemT_co = TypeVar(
"_DT64ItemT_co", bound=int | None, default=int | None, covariant=True
)
class datetime64(generic[_DT64ItemT_co], Generic[_DT64ItemT_co]): ...
GenericT_co = TypeVar("GenericT_co", bound=generic, default=Any, covariant=True)
GenericT = TypeVar("GenericT", bound=generic, default=Any)
class Series(Generic[GenericT_co]):
def to_numpy_simplified(
self, dtype: dtype[GenericT] | type[GenericT]
) -> GenericT: ...
reveal_type(Series().to_numpy_simplified(datetime64)) # mypy: datetime64[Any], pyright & pyright: datetime64[int | None]
Expected Behavior
datetime64[int | None]
Actual Behavior
datetime64[Any]
Bug Report
mypyreveals a certainnesteddefault generic type intypeasAny, while other type checkers reveal it as the default type.This issue is motivated by pandas-dev/pandas-stubs#1764.
To Reproduce
This is complicated, see #21608 (comment) for a much simplified example.
Expected Behavior
datetime64[int | None]Actual Behavior
datetime64[Any]