Skip to content

Commit 861b2fb

Browse files
authored
TYP: Enable pyright's reportInconsistentConstructor (#54398)
* Enable pyright's reportInconsistentConstructor * bump pyright without adding new errors
1 parent 476fcb1 commit 861b2fb

11 files changed

+19
-16
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ repos:
138138
types: [python]
139139
stages: [manual]
140140
additional_dependencies: &pyright_dependencies
141-
141+
142142
- id: pyright
143143
# note: assumes python env is setup and activated
144144
name: pyright reportGeneralTypeIssues

pandas/_typing.py

+3
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,6 @@ def closed(self) -> bool:
463463

464464
# to_stata
465465
ToStataByteorder = Literal[">", "<", "little", "big"]
466+
467+
# ExcelWriter
468+
ExcelWriterIfSheetExists = Literal["error", "new", "replace", "overlay"]

pandas/core/computation/ops.py

-3
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ def ndim(self) -> int:
189189

190190

191191
class Constant(Term):
192-
def __init__(self, value, env, side=None, encoding=None) -> None:
193-
super().__init__(value, env, side=side, encoding=encoding)
194-
195192
def _resolve_name(self):
196193
return self._name
197194

pandas/core/computation/pytables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ def value(self):
9393

9494

9595
class Constant(Term):
96-
def __init__(self, value, env: PyTablesScope, side=None, encoding=None) -> None:
96+
def __init__(self, name, env: PyTablesScope, side=None, encoding=None) -> None:
9797
assert isinstance(env, PyTablesScope), type(env)
98-
super().__init__(value, env, side=side, encoding=encoding)
98+
super().__init__(name, env, side=side, encoding=encoding)
9999

100100
def _resolve_name(self):
101101
return self._name

pandas/core/indexes/accessors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ class PeriodProperties(Properties):
573573
class CombinedDatetimelikeProperties(
574574
DatetimeProperties, TimedeltaProperties, PeriodProperties
575575
):
576-
def __new__(cls, data: Series):
576+
def __new__(cls, data: Series): # pyright: ignore[reportInconsistentConstructor]
577577
# CombinedDatetimelikeProperties isn't really instantiated. Instead
578578
# we need to choose which parent (datetime or timedelta) is
579579
# appropriate. Since we're checking the dtypes anyway, we'll just

pandas/io/excel/_base.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
from pandas._typing import (
7575
DtypeArg,
7676
DtypeBackend,
77+
ExcelWriterIfSheetExists,
7778
FilePath,
7879
IntStrT,
7980
ReadBuffer,
@@ -1129,7 +1130,7 @@ def __new__(
11291130
datetime_format: str | None = None,
11301131
mode: str = "w",
11311132
storage_options: StorageOptions | None = None,
1132-
if_sheet_exists: Literal["error", "new", "replace", "overlay"] | None = None,
1133+
if_sheet_exists: ExcelWriterIfSheetExists | None = None,
11331134
engine_kwargs: dict | None = None,
11341135
) -> ExcelWriter:
11351136
# only switch class if generic(ExcelWriter)
@@ -1218,7 +1219,7 @@ def __init__(
12181219
datetime_format: str | None = None,
12191220
mode: str = "w",
12201221
storage_options: StorageOptions | None = None,
1221-
if_sheet_exists: str | None = None,
1222+
if_sheet_exists: ExcelWriterIfSheetExists | None = None,
12221223
engine_kwargs: dict[str, Any] | None = None,
12231224
) -> None:
12241225
# validate that this engine can handle the extension

pandas/io/excel/_odswriter.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
if TYPE_CHECKING:
2121
from pandas._typing import (
22+
ExcelWriterIfSheetExists,
2223
FilePath,
2324
StorageOptions,
2425
WriteExcelBuffer,
@@ -39,7 +40,7 @@ def __init__(
3940
datetime_format=None,
4041
mode: str = "w",
4142
storage_options: StorageOptions | None = None,
42-
if_sheet_exists: str | None = None,
43+
if_sheet_exists: ExcelWriterIfSheetExists | None = None,
4344
engine_kwargs: dict[str, Any] | None = None,
4445
**kwargs,
4546
) -> None:

pandas/io/excel/_openpyxl.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from openpyxl.workbook import Workbook
2929

3030
from pandas._typing import (
31+
ExcelWriterIfSheetExists,
3132
FilePath,
3233
ReadBuffer,
3334
Scalar,
@@ -48,7 +49,7 @@ def __init__(
4849
datetime_format: str | None = None,
4950
mode: str = "w",
5051
storage_options: StorageOptions | None = None,
51-
if_sheet_exists: str | None = None,
52+
if_sheet_exists: ExcelWriterIfSheetExists | None = None,
5253
engine_kwargs: dict[str, Any] | None = None,
5354
**kwargs,
5455
) -> None:

pandas/io/excel/_xlsxwriter.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
if TYPE_CHECKING:
1717
from pandas._typing import (
18+
ExcelWriterIfSheetExists,
1819
FilePath,
1920
StorageOptions,
2021
WriteExcelBuffer,
@@ -189,7 +190,7 @@ def __init__(
189190
datetime_format: str | None = None,
190191
mode: str = "w",
191192
storage_options: StorageOptions | None = None,
192-
if_sheet_exists: str | None = None,
193+
if_sheet_exists: ExcelWriterIfSheetExists | None = None,
193194
engine_kwargs: dict[str, Any] | None = None,
194195
**kwargs,
195196
) -> None:

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ include = ["pandas", "typings"]
732732
exclude = ["pandas/tests", "pandas/io/clipboard", "pandas/util/version"]
733733
# enable subset of "strict"
734734
reportDuplicateImport = true
735+
reportInconsistentConstructor = true
735736
reportInvalidStubStatement = true
736737
reportOverlappingOverload = true
737738
reportPropertyTypeMismatch = true

pyright_reportGeneralTypeIssues.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# this becomes obsolete when reportGeneralTypeIssues can be enabled in pyproject.toml
21
{
32
"typeCheckingMode": "off",
43
"reportGeneralTypeIssues": true,
@@ -9,12 +8,11 @@
98
],
109
"exclude":
1110
[
12-
# exclude tests
1311
"pandas/tests",
14-
# exclude vendored files
12+
1513
"pandas/io/clipboard",
1614
"pandas/util/version",
17-
# and all files that currently don't pass
15+
1816
"pandas/_testing/__init__.py",
1917
"pandas/_testing/_hypothesis.py",
2018
"pandas/_testing/_io.py",

0 commit comments

Comments
 (0)