Skip to content

TYP: Fix typing in ExtensionDtype registry #41203

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

Merged
merged 17 commits into from
Aug 3, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pandas/core/dtypes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pandas._typing import (
DtypeObj,
NpDtype,
Union,
type_t,
)
from pandas.errors import AbstractMethodError
Expand Down Expand Up @@ -465,8 +466,8 @@ def find(
dtype_type = dtype
if issubclass(dtype_type, ExtensionDtype):
# cast needed here as mypy doesn't know we have figured
# out it is an ExtensionDtype
return cast(ExtensionDtype, dtype)
# out it is an ExtensionDtype or type_t[ExtensionDtype]
return cast(Union[ExtensionDtype, type_t[ExtensionDtype]], dtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, to avoid adding the Union import, i have a preference for,

Suggested change
return cast(Union[ExtensionDtype, type_t[ExtensionDtype]], dtype)
return cast("ExtensionDtype | type_t[ExtensionDtype]", dtype)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in next commit


return None

Expand Down