From 44c1a7f8b89ebd0c2516d3c379f746700d42701d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 3 Aug 2023 22:14:57 -0400 Subject: [PATCH 1/2] Enable pyright's reportInconsistentConstructor --- pandas/_typing.py | 3 +++ pandas/core/computation/ops.py | 3 --- pandas/core/computation/pytables.py | 4 ++-- pandas/core/indexes/accessors.py | 2 +- pandas/io/excel/_base.py | 5 +++-- pandas/io/excel/_odswriter.py | 3 ++- pandas/io/excel/_openpyxl.py | 3 ++- pandas/io/excel/_xlsxwriter.py | 3 ++- pyproject.toml | 1 + 9 files changed, 16 insertions(+), 11 deletions(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index 6a61b37ff4a94..e36175fa5a0af 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -463,3 +463,6 @@ def closed(self) -> bool: # to_stata ToStataByteorder = Literal[">", "<", "little", "big"] + +# ExcelWriter +ExcelWriterIfSheetExists = Literal["error", "new", "replace", "overlay"] diff --git a/pandas/core/computation/ops.py b/pandas/core/computation/ops.py index b14187b0cc3a5..9050fb6e76b9c 100644 --- a/pandas/core/computation/ops.py +++ b/pandas/core/computation/ops.py @@ -189,9 +189,6 @@ def ndim(self) -> int: class Constant(Term): - def __init__(self, value, env, side=None, encoding=None) -> None: - super().__init__(value, env, side=side, encoding=encoding) - def _resolve_name(self): return self._name diff --git a/pandas/core/computation/pytables.py b/pandas/core/computation/pytables.py index 433421d35af55..77d8d79506258 100644 --- a/pandas/core/computation/pytables.py +++ b/pandas/core/computation/pytables.py @@ -93,9 +93,9 @@ def value(self): class Constant(Term): - def __init__(self, value, env: PyTablesScope, side=None, encoding=None) -> None: + def __init__(self, name, env: PyTablesScope, side=None, encoding=None) -> None: assert isinstance(env, PyTablesScope), type(env) - super().__init__(value, env, side=side, encoding=encoding) + super().__init__(name, env, side=side, encoding=encoding) def _resolve_name(self): return self._name diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index c6da7d847c363..d972983532e3c 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -573,7 +573,7 @@ class PeriodProperties(Properties): class CombinedDatetimelikeProperties( DatetimeProperties, TimedeltaProperties, PeriodProperties ): - def __new__(cls, data: Series): + def __new__(cls, data: Series): # pyright: ignore[reportInconsistentConstructor] # CombinedDatetimelikeProperties isn't really instantiated. Instead # we need to choose which parent (datetime or timedelta) is # appropriate. Since we're checking the dtypes anyway, we'll just diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 7c67f85ed3d1e..1024b52b0c416 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -74,6 +74,7 @@ from pandas._typing import ( DtypeArg, DtypeBackend, + ExcelWriterIfSheetExists, FilePath, IntStrT, ReadBuffer, @@ -1129,7 +1130,7 @@ def __new__( datetime_format: str | None = None, mode: str = "w", storage_options: StorageOptions | None = None, - if_sheet_exists: Literal["error", "new", "replace", "overlay"] | None = None, + if_sheet_exists: ExcelWriterIfSheetExists | None = None, engine_kwargs: dict | None = None, ) -> ExcelWriter: # only switch class if generic(ExcelWriter) @@ -1218,7 +1219,7 @@ def __init__( datetime_format: str | None = None, mode: str = "w", storage_options: StorageOptions | None = None, - if_sheet_exists: str | None = None, + if_sheet_exists: ExcelWriterIfSheetExists | None = None, engine_kwargs: dict[str, Any] | None = None, ) -> None: # validate that this engine can handle the extension diff --git a/pandas/io/excel/_odswriter.py b/pandas/io/excel/_odswriter.py index a4b4d965089dc..391103dd477f1 100644 --- a/pandas/io/excel/_odswriter.py +++ b/pandas/io/excel/_odswriter.py @@ -19,6 +19,7 @@ if TYPE_CHECKING: from pandas._typing import ( + ExcelWriterIfSheetExists, FilePath, StorageOptions, WriteExcelBuffer, @@ -39,7 +40,7 @@ def __init__( datetime_format=None, mode: str = "w", storage_options: StorageOptions | None = None, - if_sheet_exists: str | None = None, + if_sheet_exists: ExcelWriterIfSheetExists | None = None, engine_kwargs: dict[str, Any] | None = None, **kwargs, ) -> None: diff --git a/pandas/io/excel/_openpyxl.py b/pandas/io/excel/_openpyxl.py index 8ca2c098cd426..89f04be32b9bc 100644 --- a/pandas/io/excel/_openpyxl.py +++ b/pandas/io/excel/_openpyxl.py @@ -28,6 +28,7 @@ from openpyxl.workbook import Workbook from pandas._typing import ( + ExcelWriterIfSheetExists, FilePath, ReadBuffer, Scalar, @@ -48,7 +49,7 @@ def __init__( datetime_format: str | None = None, mode: str = "w", storage_options: StorageOptions | None = None, - if_sheet_exists: str | None = None, + if_sheet_exists: ExcelWriterIfSheetExists | None = None, engine_kwargs: dict[str, Any] | None = None, **kwargs, ) -> None: diff --git a/pandas/io/excel/_xlsxwriter.py b/pandas/io/excel/_xlsxwriter.py index d7c29a812c2b7..afa988a5eda51 100644 --- a/pandas/io/excel/_xlsxwriter.py +++ b/pandas/io/excel/_xlsxwriter.py @@ -15,6 +15,7 @@ if TYPE_CHECKING: from pandas._typing import ( + ExcelWriterIfSheetExists, FilePath, StorageOptions, WriteExcelBuffer, @@ -189,7 +190,7 @@ def __init__( datetime_format: str | None = None, mode: str = "w", storage_options: StorageOptions | None = None, - if_sheet_exists: str | None = None, + if_sheet_exists: ExcelWriterIfSheetExists | None = None, engine_kwargs: dict[str, Any] | None = None, **kwargs, ) -> None: diff --git a/pyproject.toml b/pyproject.toml index 75a33e2a5269c..e98030217987d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -732,6 +732,7 @@ include = ["pandas", "typings"] exclude = ["pandas/tests", "pandas/io/clipboard", "pandas/util/version"] # enable subset of "strict" reportDuplicateImport = true +reportInconsistentConstructor = true reportInvalidStubStatement = true reportOverlappingOverload = true reportPropertyTypeMismatch = true From c028de98cf09b76e56cdfe0fa9a18bc2e3ebcb3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Fri, 4 Aug 2023 12:42:53 -0400 Subject: [PATCH 2/2] bump pyright without adding new errors --- .pre-commit-config.yaml | 2 +- pyright_reportGeneralTypeIssues.json | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 15bdc816ee65c..dc1ae4bd99612 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -138,7 +138,7 @@ repos: types: [python] stages: [manual] additional_dependencies: &pyright_dependencies - - pyright@1.1.296 + - pyright@1.1.305 - id: pyright # note: assumes python env is setup and activated name: pyright reportGeneralTypeIssues diff --git a/pyright_reportGeneralTypeIssues.json b/pyright_reportGeneralTypeIssues.json index 761018c3ce496..b5baab8c33471 100644 --- a/pyright_reportGeneralTypeIssues.json +++ b/pyright_reportGeneralTypeIssues.json @@ -1,4 +1,3 @@ -# this becomes obsolete when reportGeneralTypeIssues can be enabled in pyproject.toml { "typeCheckingMode": "off", "reportGeneralTypeIssues": true, @@ -9,12 +8,11 @@ ], "exclude": [ - # exclude tests "pandas/tests", - # exclude vendored files + "pandas/io/clipboard", "pandas/util/version", - # and all files that currently don't pass + "pandas/_testing/__init__.py", "pandas/_testing/_hypothesis.py", "pandas/_testing/_io.py",