Skip to content

Commit b685e3f

Browse files
committed
PLC0105
1 parent cbe97dd commit b685e3f

File tree

5 files changed

+65
-42
lines changed

5 files changed

+65
-42
lines changed

pandas-stubs/_typing.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,8 +911,10 @@ SeriesDType: TypeAlias = (
911911
S1 = TypeVar("S1", bound=SeriesDType, default=Any)
912912
# Like S1, but without `default=Any`.
913913
S2 = TypeVar("S2", bound=SeriesDType)
914-
S2_CT = TypeVar("S2_CT", bound=SeriesDType, contravariant=True)
915-
S2_CT_NDT = TypeVar("S2_CT_NDT", bound=SeriesDTypeNoDateTime, contravariant=True)
914+
S2_contra = TypeVar("S2_contra", bound=SeriesDType, contravariant=True)
915+
S2_NDT_contra = TypeVar(
916+
"S2_NDT_contra", bound=SeriesDTypeNoDateTime, contravariant=True
917+
)
916918
S2_NSDT = TypeVar("S2_NSDT", bound=SeriesDTypeNoStrDateTime)
917919
S3 = TypeVar("S3", bound=SeriesDType)
918920

pandas-stubs/core/frame.pyi

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ from pandas._typing import (
169169
from pandas.io.formats.style import Styler
170170
from pandas.plotting import PlotAccessor
171171

172-
_T_MUTABLE_MAPPING = TypeVar("_T_MUTABLE_MAPPING", bound=MutableMapping, covariant=True)
172+
_T_MUTABLE_MAPPING_co = TypeVar(
173+
"_T_MUTABLE_MAPPING_co", bound=MutableMapping, covariant=True
174+
)
173175

174176
class _iLocIndexerFrame(_iLocIndexer, Generic[_T]):
175177
@overload
@@ -463,9 +465,9 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
463465
self,
464466
orient: Literal["records"],
465467
*,
466-
into: _T_MUTABLE_MAPPING | type[_T_MUTABLE_MAPPING],
468+
into: _T_MUTABLE_MAPPING_co | type[_T_MUTABLE_MAPPING_co],
467469
index: Literal[True] = ...,
468-
) -> list[_T_MUTABLE_MAPPING]: ...
470+
) -> list[_T_MUTABLE_MAPPING_co]: ...
469471
@overload
470472
def to_dict(
471473
self,
@@ -511,9 +513,9 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
511513
self,
512514
orient: Literal["dict", "list", "series"] = ...,
513515
*,
514-
into: _T_MUTABLE_MAPPING | type[_T_MUTABLE_MAPPING],
516+
into: _T_MUTABLE_MAPPING_co | type[_T_MUTABLE_MAPPING_co],
515517
index: Literal[True] = ...,
516-
) -> _T_MUTABLE_MAPPING: ...
518+
) -> _T_MUTABLE_MAPPING_co: ...
517519
@overload
518520
def to_dict(
519521
self,

pandas-stubs/core/indexes/base.pyi

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ from pandas._typing import (
6363
C2,
6464
S1,
6565
S2,
66-
S2_CT,
6766
S2_NSDT,
6867
T_COMPLEX,
6968
AnyAll,
@@ -85,6 +84,7 @@ from pandas._typing import (
8584
MaskType,
8685
NaPosition,
8786
ReindexMethod,
87+
S2_contra,
8888
Scalar,
8989
SequenceNotStr,
9090
SliceType,
@@ -520,8 +520,8 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
520520
) -> Index[S2]: ...
521521
@overload
522522
def __add__(
523-
self: Index[S2_CT],
524-
other: SupportsRAdd[S2_CT, S2] | Sequence[SupportsRAdd[S2_CT, S2]],
523+
self: Index[S2_contra],
524+
other: SupportsRAdd[S2_contra, S2] | Sequence[SupportsRAdd[S2_contra, S2]],
525525
) -> Index[S2]: ...
526526
@overload
527527
def __add__(
@@ -573,8 +573,8 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
573573
) -> Index[S2]: ...
574574
@overload
575575
def __radd__(
576-
self: Index[S2_CT],
577-
other: SupportsAdd[S2_CT, S2] | Sequence[SupportsAdd[S2_CT, S2]],
576+
self: Index[S2_contra],
577+
other: SupportsAdd[S2_contra, S2] | Sequence[SupportsAdd[S2_contra, S2]],
578578
) -> Index[S2]: ...
579579
@overload
580580
def __radd__(
@@ -789,8 +789,11 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
789789
) -> Index[S2]: ...
790790
@overload
791791
def __mul__(
792-
self: Index[S2_CT],
793-
other: SupportsRMul[S2_CT, S2_NSDT] | Sequence[SupportsRMul[S2_CT, S2_NSDT]],
792+
self: Index[S2_contra],
793+
other: (
794+
SupportsRMul[S2_contra, S2_NSDT]
795+
| Sequence[SupportsRMul[S2_contra, S2_NSDT]]
796+
),
794797
) -> Index[S2_NSDT]: ...
795798
@overload
796799
def __mul__(
@@ -853,8 +856,10 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
853856
) -> Index[S2]: ...
854857
@overload
855858
def __rmul__(
856-
self: Index[S2_CT],
857-
other: SupportsMul[S2_CT, S2_NSDT] | Sequence[SupportsMul[S2_CT, S2_NSDT]],
859+
self: Index[S2_contra],
860+
other: (
861+
SupportsMul[S2_contra, S2_NSDT] | Sequence[SupportsMul[S2_contra, S2_NSDT]]
862+
),
858863
) -> Index[S2_NSDT]: ...
859864
@overload
860865
def __rmul__(

pandas-stubs/core/series.pyi

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ from pandas._libs.tslibs.nattype import NaTType
120120
from pandas._typing import (
121121
S1,
122122
S2,
123-
S2_CT,
124-
S2_CT_NDT,
125123
S2_NSDT,
126124
T_COMPLEX,
127125
AggFuncTypeBase,
@@ -180,6 +178,8 @@ from pandas._typing import (
180178
ReindexMethod,
181179
Renamer,
182180
ReplaceValue,
181+
S2_contra,
182+
S2_NDT_contra,
183183
Scalar,
184184
ScalarT,
185185
SequenceNotStr,
@@ -1725,14 +1725,16 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
17251725
) -> Series[Timedelta]: ...
17261726
@overload
17271727
def __add__(
1728-
self: Supports_ProtoAdd[S2_CT, S2], other: S2_CT | Sequence[S2_CT]
1728+
self: Supports_ProtoAdd[S2_contra, S2], other: S2_contra | Sequence[S2_contra]
17291729
) -> Series[S2]: ...
17301730
@overload
1731-
def __add__(self: Series[S2_CT], other: SupportsRAdd[S2_CT, S2]) -> Series[S2]: ...
1731+
def __add__(
1732+
self: Series[S2_contra], other: SupportsRAdd[S2_contra, S2]
1733+
) -> Series[S2]: ...
17321734
# pandas-dev/pandas#62353
17331735
@overload
17341736
def __add__(
1735-
self: Series[S2_CT_NDT], other: Sequence[SupportsRAdd[S2_CT_NDT, S2]]
1737+
self: Series[S2_NDT_contra], other: Sequence[SupportsRAdd[S2_NDT_contra, S2]]
17361738
) -> Series[S2]: ...
17371739
@overload
17381740
def __add__(
@@ -1835,16 +1837,16 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
18351837
) -> Series[Timedelta]: ...
18361838
@overload
18371839
def add(
1838-
self: Supports_ProtoAdd[S2_CT, S2],
1839-
other: S2_CT | Sequence[S2_CT],
1840+
self: Supports_ProtoAdd[S2_contra, S2],
1841+
other: S2_contra | Sequence[S2_contra],
18401842
level: Level | None = None,
18411843
fill_value: float | None = None,
18421844
axis: int = 0,
18431845
) -> Series[S2]: ...
18441846
@overload
18451847
def add(
1846-
self: Series[S2_CT],
1847-
other: SupportsRAdd[S2_CT, S2] | Sequence[SupportsRAdd[S2_CT, S2]],
1848+
self: Series[S2_contra],
1849+
other: SupportsRAdd[S2_contra, S2] | Sequence[SupportsRAdd[S2_contra, S2]],
18481850
level: Level | None = None,
18491851
fill_value: float | None = None,
18501852
axis: int = 0,
@@ -1952,14 +1954,16 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
19521954
# pyright is unhappy without the above 3 overloads
19531955
@overload
19541956
def __radd__(
1955-
self: Supports_ProtoRAdd[S2_CT, S2], other: S2_CT | Sequence[S2_CT]
1957+
self: Supports_ProtoRAdd[S2_contra, S2], other: S2_contra | Sequence[S2_contra]
19561958
) -> Series[S2]: ...
19571959
@overload
1958-
def __radd__(self: Series[S2_CT], other: SupportsAdd[S2_CT, S2]) -> Series[S2]: ...
1960+
def __radd__(
1961+
self: Series[S2_contra], other: SupportsAdd[S2_contra, S2]
1962+
) -> Series[S2]: ...
19591963
# pandas-dev/pandas#62353
19601964
@overload
19611965
def __radd__(
1962-
self: Series[S2_CT_NDT], other: Sequence[SupportsAdd[S2_CT_NDT, S2]]
1966+
self: Series[S2_NDT_contra], other: Sequence[SupportsAdd[S2_NDT_contra, S2]]
19631967
) -> Series[S2]: ...
19641968
@overload
19651969
def __radd__(
@@ -2066,16 +2070,16 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
20662070
) -> Series[Timedelta]: ...
20672071
@overload
20682072
def radd(
2069-
self: Supports_ProtoRAdd[S2_CT, S2],
2070-
other: S2_CT | Sequence[S2_CT],
2073+
self: Supports_ProtoRAdd[S2_contra, S2],
2074+
other: S2_contra | Sequence[S2_contra],
20712075
level: Level | None = None,
20722076
fill_value: float | None = None,
20732077
axis: int = 0,
20742078
) -> Series[S2]: ...
20752079
@overload
20762080
def radd(
2077-
self: Series[S2_CT],
2078-
other: SupportsAdd[S2_CT, S2] | Sequence[SupportsAdd[S2_CT, S2]],
2081+
self: Series[S2_contra],
2082+
other: SupportsAdd[S2_contra, S2] | Sequence[SupportsAdd[S2_contra, S2]],
20792083
level: Level | None = None,
20802084
fill_value: float | None = None,
20812085
axis: int = 0,
@@ -2532,8 +2536,11 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
25322536
) -> Series[S2]: ...
25332537
@overload
25342538
def __mul__(
2535-
self: Series[S2_CT],
2536-
other: SupportsRMul[S2_CT, S2_NSDT] | Sequence[SupportsRMul[S2_CT, S2_NSDT]],
2539+
self: Series[S2_contra],
2540+
other: (
2541+
SupportsRMul[S2_contra, S2_NSDT]
2542+
| Sequence[SupportsRMul[S2_contra, S2_NSDT]]
2543+
),
25372544
) -> Series[S2_NSDT]: ...
25382545
@overload
25392546
def __mul__(
@@ -2625,8 +2632,11 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
26252632
) -> Series[S2]: ...
26262633
@overload
26272634
def mul(
2628-
self: Series[S2_CT],
2629-
other: SupportsRMul[S2_CT, S2_NSDT] | Sequence[SupportsRMul[S2_CT, S2_NSDT]],
2635+
self: Series[S2_contra],
2636+
other: (
2637+
SupportsRMul[S2_contra, S2_NSDT]
2638+
| Sequence[SupportsRMul[S2_contra, S2_NSDT]]
2639+
),
26302640
level: Level | None = None,
26312641
fill_value: float | None = None,
26322642
axis: int = 0,
@@ -2742,8 +2752,10 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
27422752
) -> Series[S2]: ...
27432753
@overload
27442754
def __rmul__(
2745-
self: Series[S2_CT],
2746-
other: SupportsMul[S2_CT, S2_NSDT] | Sequence[SupportsMul[S2_CT, S2_NSDT]],
2755+
self: Series[S2_contra],
2756+
other: (
2757+
SupportsMul[S2_contra, S2_NSDT] | Sequence[SupportsMul[S2_contra, S2_NSDT]]
2758+
),
27472759
) -> Series[S2_NSDT]: ...
27482760
@overload
27492761
def __rmul__(
@@ -2835,8 +2847,10 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
28352847
) -> Series[S2]: ...
28362848
@overload
28372849
def rmul(
2838-
self: Series[S2_CT],
2839-
other: SupportsMul[S2_CT, S2_NSDT] | Sequence[SupportsMul[S2_CT, S2_NSDT]],
2850+
self: Series[S2_contra],
2851+
other: (
2852+
SupportsMul[S2_contra, S2_NSDT] | Sequence[SupportsMul[S2_contra, S2_NSDT]]
2853+
),
28402854
level: Level | None = None,
28412855
fill_value: float | None = None,
28422856
axis: int = 0,

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ skip_glob = "env"
172172

173173
[tool.ruff]
174174
target-version = "py310"
175-
fix = false
175+
fix = true
176176

177177

178178
[tool.ruff.lint]
@@ -201,7 +201,7 @@ ignore = [
201201
"A004", # https://docs.astral.sh/ruff/rules/builtin-import-shadowing/
202202
"PYI001", # https://docs.astral.sh/ruff/rules/unprefixed-type-param/
203203
"PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/
204-
"ERA001", "ANN001", "ANN201", "ANN204", "PLR0402", "PLC0105"
204+
"ERA001", "ANN001", "ANN201", "ANN204", "PLR0402",
205205
]
206206
"scripts/*" = [
207207
# The following rules are ignored permanently for good reasons

0 commit comments

Comments
 (0)