Skip to content

Generic default type in type revealed as Any #21608

Description

@cmp0xff

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.

fromtypingimportAny, Generic, TypeVar, reveal_type_ItemT_co=TypeVar("_ItemT_co", default=Any, covariant=True)
classgeneric(Generic[_ItemT_co]): ...
_ScalarT_co=TypeVar("_ScalarT_co", bound=generic, default=Any, covariant=True)
classdtype(Generic[_ScalarT_co]): ...
_DT64ItemT_co=TypeVar(
"_DT64ItemT_co", bound=int|None, default=int|None, covariant=True
)
classdatetime64(generic[_DT64ItemT_co], Generic[_DT64ItemT_co]): ...
GenericT_co=TypeVar("GenericT_co", bound=generic, default=Any, covariant=True)
GenericT=TypeVar("GenericT", bound=generic, default=Any)
classSeries(Generic[GenericT_co]):
defto_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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-pep-696TypeVar defaults

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions