Skip to content

Commit 9ff3322

Browse files
authored
TYP: update mypy and small pyi fixes from ruff (#54085)
* TYP: update mypy and small pyi fixes from ruff * fix errors * use pyright ignore comment (would prefer 'as TypeGuard') * disable PLC0414 * Revert "disable PLC0414" This reverts commit c0f7b2b.
1 parent 7d0b0e2 commit 9ff3322

File tree

10 files changed

+33
-23
lines changed

10 files changed

+33
-23
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
hooks:
2222
- id: black
2323
- repo: https://github.com/astral-sh/ruff-pre-commit
24-
rev: v0.0.275
24+
rev: v0.0.277
2525
hooks:
2626
- id: ruff
2727
args: [--exit-non-zero-on-fix]
@@ -130,7 +130,7 @@ repos:
130130
types: [python]
131131
stages: [manual]
132132
additional_dependencies: &pyright_dependencies
133-
- pyright@1.1.292
133+
- pyright@1.1.296
134134
- id: pyright_reportGeneralTypeIssues
135135
# note: assumes python env is setup and activated
136136
name: pyright reportGeneralTypeIssues

doc/source/whatsnew/v2.1.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ If installed, we now require:
171171
+=================+=================+==========+=========+
172172
| numpy | 1.21.6 | X | X |
173173
+-----------------+-----------------+----------+---------+
174-
| mypy (dev) | 1.2 | | X |
174+
| mypy (dev) | 1.4.1 | | X |
175175
+-----------------+-----------------+----------+---------+
176176
| beautifulsoup4 | 4.11.1 | | X |
177177
+-----------------+-----------------+----------+---------+

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ dependencies:
7676

7777
# code checks
7878
- flake8=6.0.0 # run in subprocess over docstring examples
79-
- mypy=1.2 # pre-commit uses locally installed mypy
79+
- mypy=1.4.1 # pre-commit uses locally installed mypy
8080
- tokenize-rt # scripts/check_for_inconsistent_pandas_namespace.py
8181
- pre-commit>=2.15.0
8282

pandas/_libs/lib.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ from enum import Enum
3030
class _NoDefault(Enum):
3131
no_default = ...
3232

33-
no_default: Final = _NoDefault.no_default # noqa: PYI015
33+
no_default: Final = _NoDefault.no_default
3434
NoDefault = Literal[_NoDefault.no_default]
3535

3636
i8max: int

pandas/_libs/sas.pyi

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from typing import TYPE_CHECKING
2-
3-
if TYPE_CHECKING:
4-
from pandas.io.sas.sas7bdat import SAS7BDATReader
1+
from pandas.io.sas.sas7bdat import SAS7BDATReader
52

63
class Parser:
74
def __init__(self, parser: SAS7BDATReader) -> None: ...

pandas/_typing.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@
8484
NumpySorter = Optional[npt._ArrayLikeInt_co] # type: ignore[name-defined]
8585

8686
if sys.version_info >= (3, 10):
87-
from typing import TypeGuard
87+
from typing import TypeGuard # pyright: ignore[reportUnusedImport]
8888
else:
89-
from typing_extensions import TypeGuard # pyright: reportUnusedImport = false
89+
from typing_extensions import TypeGuard # pyright: ignore[reportUnusedImport]
9090

9191
if sys.version_info >= (3, 11):
9292
from typing import Self
9393
else:
94-
from typing_extensions import Self # pyright: reportUnusedImport = false
94+
from typing_extensions import Self # pyright: ignore[reportUnusedImport]
9595
else:
9696
npt: Any = None
9797
Self: Any = None

pandas/core/dtypes/missing.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
from pandas.core.dtypes.inference import is_list_like
4747

4848
if TYPE_CHECKING:
49+
from re import Pattern
50+
4951
from pandas._typing import (
5052
ArrayLike,
5153
DtypeObj,
@@ -69,7 +71,7 @@
6971

7072

7173
@overload
72-
def isna(obj: Scalar) -> bool:
74+
def isna(obj: Scalar | Pattern) -> bool:
7375
...
7476

7577

pandas/core/series.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
Any,
1919
Callable,
2020
Literal,
21-
Union,
2221
cast,
2322
overload,
2423
)
@@ -3459,7 +3458,7 @@ def sort_values(
34593458
self,
34603459
*,
34613460
axis: Axis = ...,
3462-
ascending: bool | int | Sequence[bool] | Sequence[int] = ...,
3461+
ascending: bool | Sequence[bool] = ...,
34633462
inplace: Literal[False] = ...,
34643463
kind: SortKind = ...,
34653464
na_position: NaPosition = ...,
@@ -3473,7 +3472,7 @@ def sort_values(
34733472
self,
34743473
*,
34753474
axis: Axis = ...,
3476-
ascending: bool | int | Sequence[bool] | Sequence[int] = ...,
3475+
ascending: bool | Sequence[bool] = ...,
34773476
inplace: Literal[True],
34783477
kind: SortKind = ...,
34793478
na_position: NaPosition = ...,
@@ -3482,11 +3481,25 @@ def sort_values(
34823481
) -> None:
34833482
...
34843483

3484+
@overload
3485+
def sort_values(
3486+
self,
3487+
*,
3488+
axis: Axis = ...,
3489+
ascending: bool | Sequence[bool] = ...,
3490+
inplace: bool = ...,
3491+
kind: SortKind = ...,
3492+
na_position: NaPosition = ...,
3493+
ignore_index: bool = ...,
3494+
key: ValueKeyFunc = ...,
3495+
) -> Series | None:
3496+
...
3497+
34853498
def sort_values(
34863499
self,
34873500
*,
34883501
axis: Axis = 0,
3489-
ascending: bool | int | Sequence[bool] | Sequence[int] = True,
3502+
ascending: bool | Sequence[bool] = True,
34903503
inplace: bool = False,
34913504
kind: SortKind = "quicksort",
34923505
na_position: NaPosition = "last",
@@ -3647,7 +3660,7 @@ def sort_values(
36473660
)
36483661

36493662
if is_list_like(ascending):
3650-
ascending = cast(Sequence[Union[bool, int]], ascending)
3663+
ascending = cast(Sequence[bool], ascending)
36513664
if len(ascending) != 1:
36523665
raise ValueError(
36533666
f"Length of ascending ({len(ascending)}) must be 1 for Series"

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ moto
5353
flask
5454
asv>=0.5.1
5555
flake8==6.0.0
56-
mypy==1.2
56+
mypy==1.4.1
5757
tokenize-rt
5858
pre-commit>=2.15.0
5959
gitpython

typings/numba.pyi

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# pyright: reportIncompleteStub = false
22
from typing import (
3-
TYPE_CHECKING,
43
Any,
54
Callable,
65
Literal,
76
overload,
87
)
98

10-
if TYPE_CHECKING:
11-
import numba
9+
import numba
1210

13-
from pandas._typing import F
11+
from pandas._typing import F
1412

1513
def __getattr__(name: str) -> Any: ... # incomplete
1614
@overload

0 commit comments

Comments
 (0)