Skip to content

Commit 2b9ca07

Browse files
authored
STY: Bump pyright, pyupgrade and mypy for new PEP-696 syntax (#60006)
* STY: Bump pyright, pyupgrade and mypy for new PEP-696 syntax * Apply update * fix & ignore failures * another ignore
1 parent 97c4ce3 commit 2b9ca07

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+78
-84
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ repos:
7474
hooks:
7575
- id: isort
7676
- repo: https://github.com/asottile/pyupgrade
77-
rev: v3.16.0
77+
rev: v3.17.0
7878
hooks:
7979
- id: pyupgrade
8080
args: [--py310-plus]
@@ -112,7 +112,7 @@ repos:
112112
types: [python]
113113
stages: [manual]
114114
additional_dependencies: &pyright_dependencies
115-
115+
116116
- id: pyright
117117
# note: assumes python env is setup and activated
118118
name: pyright reportGeneralTypeIssues

environment.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ dependencies:
7676
- cxx-compiler
7777

7878
# code checks
79-
- flake8=6.1.0 # run in subprocess over docstring examples
80-
- mypy=1.9.0 # pre-commit uses locally installed mypy
79+
- flake8=7.1.0 # run in subprocess over docstring examples
80+
- mypy=1.11.2 # pre-commit uses locally installed mypy
8181
- tokenize-rt # scripts/check_for_inconsistent_pandas_namespace.py
82-
- pre-commit>=3.6.0
82+
- pre-commit>=4.0.1
8383

8484
# documentation
8585
- gitpython # obtain contributors from git for whatsnew

pandas/_config/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def __dir__(self) -> list[str]:
411411

412412

413413
@contextmanager
414-
def option_context(*args) -> Generator[None, None, None]:
414+
def option_context(*args) -> Generator[None]:
415415
"""
416416
Context manager to temporarily set options in a ``with`` statement.
417417
@@ -718,7 +718,7 @@ def _build_option_description(k: str) -> str:
718718

719719

720720
@contextmanager
721-
def config_prefix(prefix: str) -> Generator[None, None, None]:
721+
def config_prefix(prefix: str) -> Generator[None]:
722722
"""
723723
contextmanager for multiple invocations of API with a common prefix
724724

pandas/_config/localization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
@contextmanager
2626
def set_locale(
2727
new_locale: str | tuple[str, str], lc_var: int = locale.LC_ALL
28-
) -> Generator[str | tuple[str, str], None, None]:
28+
) -> Generator[str | tuple[str, str]]:
2929
"""
3030
Context manager for temporarily setting a locale.
3131

pandas/_testing/_warnings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def assert_produces_warning(
3535
raise_on_extra_warnings: bool = True,
3636
match: str | tuple[str | None, ...] | None = None,
3737
must_find_all_warnings: bool = True,
38-
) -> Generator[list[warnings.WarningMessage], None, None]:
38+
) -> Generator[list[warnings.WarningMessage]]:
3939
"""
4040
Context manager for running code expected to either raise a specific warning,
4141
multiple specific warnings, or not raise any warnings. Verifies that the code

pandas/_testing/contexts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
@contextmanager
3030
def decompress_file(
3131
path: FilePath | BaseBuffer, compression: CompressionOptions
32-
) -> Generator[IO[bytes], None, None]:
32+
) -> Generator[IO[bytes]]:
3333
"""
3434
Open a compressed file and return a file object.
3535
@@ -50,7 +50,7 @@ def decompress_file(
5050

5151

5252
@contextmanager
53-
def set_timezone(tz: str) -> Generator[None, None, None]:
53+
def set_timezone(tz: str) -> Generator[None]:
5454
"""
5555
Context manager for temporarily setting a timezone.
5656
@@ -92,7 +92,7 @@ def setTZ(tz) -> None:
9292

9393

9494
@contextmanager
95-
def ensure_clean(filename=None) -> Generator[Any, None, None]:
95+
def ensure_clean(filename=None) -> Generator[Any]:
9696
"""
9797
Gets a temporary path and agrees to remove on close.
9898
@@ -124,7 +124,7 @@ def ensure_clean(filename=None) -> Generator[Any, None, None]:
124124

125125

126126
@contextmanager
127-
def with_csv_dialect(name: str, **kwargs) -> Generator[None, None, None]:
127+
def with_csv_dialect(name: str, **kwargs) -> Generator[None]:
128128
"""
129129
Context manager to temporarily register a CSV dialect for parsing CSV.
130130

pandas/compat/pickle_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def loads(
131131

132132

133133
@contextlib.contextmanager
134-
def patch_pickle() -> Generator[None, None, None]:
134+
def patch_pickle() -> Generator[None]:
135135
"""
136136
Temporarily patch pickle to use our unpickler.
137137
"""

pandas/core/apply.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,8 @@ def transform(self) -> DataFrame | Series:
246246
and not obj.empty
247247
):
248248
raise ValueError("Transform function failed")
249-
# error: Argument 1 to "__get__" of "AxisProperty" has incompatible type
250-
# "Union[Series, DataFrame, GroupBy[Any], SeriesGroupBy,
251-
# DataFrameGroupBy, BaseWindow, Resampler]"; expected "Union[DataFrame,
252-
# Series]"
253249
if not isinstance(result, (ABCSeries, ABCDataFrame)) or not result.index.equals(
254-
obj.index # type: ignore[arg-type]
250+
obj.index
255251
):
256252
raise ValueError("Function did not transform")
257253

@@ -803,7 +799,7 @@ def result_columns(self) -> Index:
803799

804800
@property
805801
@abc.abstractmethod
806-
def series_generator(self) -> Generator[Series, None, None]:
802+
def series_generator(self) -> Generator[Series]:
807803
pass
808804

809805
@staticmethod
@@ -1128,7 +1124,7 @@ class FrameRowApply(FrameApply):
11281124
axis: AxisInt = 0
11291125

11301126
@property
1131-
def series_generator(self) -> Generator[Series, None, None]:
1127+
def series_generator(self) -> Generator[Series]:
11321128
return (self.obj._ixs(i, axis=1) for i in range(len(self.columns)))
11331129

11341130
@staticmethod
@@ -1235,7 +1231,7 @@ def apply_broadcast(self, target: DataFrame) -> DataFrame:
12351231
return result.T
12361232

12371233
@property
1238-
def series_generator(self) -> Generator[Series, None, None]:
1234+
def series_generator(self) -> Generator[Series]:
12391235
values = self.values
12401236
values = ensure_wrapped_if_datetimelike(values)
12411237
assert len(values) > 0

pandas/core/arraylike.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,12 @@ def _reconstruct(result):
403403
# for np.<ufunc>(..) calls
404404
# kwargs cannot necessarily be handled block-by-block, so only
405405
# take this path if there are no kwargs
406-
mgr = inputs[0]._mgr
406+
mgr = inputs[0]._mgr # pyright: ignore[reportGeneralTypeIssues]
407407
result = mgr.apply(getattr(ufunc, method))
408408
else:
409409
# otherwise specific ufunc methods (eg np.<ufunc>.accumulate(..))
410410
# Those can have an axis keyword and thus can't be called block-by-block
411-
result = default_array_ufunc(inputs[0], ufunc, method, *inputs, **kwargs)
411+
result = default_array_ufunc(inputs[0], ufunc, method, *inputs, **kwargs) # pyright: ignore[reportGeneralTypeIssues]
412412
# e.g. np.negative (only one reached), with "where" and "out" in kwargs
413413

414414
result = reconstruct(result)

pandas/core/arrays/arrow/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,7 @@ def _str_rindex(self, sub: str, start: int = 0, end: int | None = None) -> Self:
24282428
result = self._apply_elementwise(predicate)
24292429
return type(self)(pa.chunked_array(result))
24302430

2431-
def _str_normalize(self, form: str) -> Self:
2431+
def _str_normalize(self, form: Literal["NFC", "NFD", "NFKC", "NFKD"]) -> Self:
24322432
predicate = lambda val: unicodedata.normalize(form, val)
24332433
result = self._apply_elementwise(predicate)
24342434
return type(self)(pa.chunked_array(result))

0 commit comments

Comments
 (0)