-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP/CI: bump mypy&pyright #46905
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
TYP/CI: bump mypy&pyright #46905
Conversation
yield ".".join(normalized_locale) | ||
# error: Argument 1 to "join" of "str" has incompatible type | ||
# "Tuple[Optional[str], Optional[str]]"; expected "Iterable[str]" | ||
yield ".".join(normalized_locale) # type: ignore[arg-type] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mypy doesn't seem to understand all(...)
to narrow the type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this works, but let's not do this yet! (until we can use it elsewhere)
def all_not_none(arg: Iterable[str | None]) -> TypeGuard[Iterable[str]]:
return all(x is not None for x in arg)
if all_not_none(normalized_locale):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking through the code there are a couple of other places this pattern is used that do not use all_not_none
from pandas/core/common.py
maybe change this one here, then in the future we only need the TypeGuard in one place.
try:
import pandas.core.common as com
locale.setlocale(lc_var, new_locale)
normalized_locale = locale.getlocale()
if com.all_not_none(*normalized_locale):
note need to prevent circular import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have there been discussions about using typing_extensions
? Then we could already use TypeGuard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no we don't use typing_extensions but we can import from typing in pandas._typing with a guard so that it resolves to Any in older python versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have there been discussions about using
typing_extensions
?
As long as typing_extensions
is not a run-time dependency, I would not be adverse to it being added as a dev dependency.
Marking as draft until mypy 0.950 is available through conda |
Co-authored-by: Simon Hawkins <[email protected]>
mypy 0.950 is now available on conda-forge :) |
@@ -957,7 +957,7 @@ def equals(self, other) -> bool: | |||
return array_equivalent(left, right, dtype_equal=True) | |||
|
|||
def _quantile( | |||
self: BaseMaskedArrayT, qs: npt.NDArray[np.float64], interpolation: str | |||
self, qs: npt.NDArray[np.float64], interpolation: str | |||
) -> BaseMaskedArray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pyright didn't previously find this. I assume the return value can be any BaseMaskedArray
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. maybe add type annotations to _maybe_mask_result
also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be follow-on. I suspect that _maybe_mask_result
should probably return the same type, but since we use explicit Subclass constructors this would not be the case if we subclass further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will leave this out - it would require quite a few ignore comments if we do something like:
@overload
def _maybe_mask_result(self, result: ArrayLike, mask: ArrayLike) -> ArrayLike:
...
@overload
def _maybe_mask_result(
self, result: tuple[ArrayLike, ArrayLike], mask: ArrayLike
) -> tuple[ArrayLike, ArrayLike]:
...
def _maybe_mask_result(
self, result: ArrayLike | tuple[ArrayLike, ArrayLike], mask: ArrayLike
) -> ArrayLike | tuple[ArrayLike, ArrayLike]:
For example FloatingArray
and BooleanArray
require an ndarray not an ExtensionArray.
doc-test failure seems to be unrelated but mypy&pyright passed :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @twoertwein lgtm pending green ci.
@twoertwein planning to restart the ci here once #47015 is green and merged, so nothing more to do here as far as i'm concerned. |
Mypy aims to have a monthly release.