From 0fcf62d3572ab4ac01fb9187cf346aad2685f090 Mon Sep 17 00:00:00 2001 From: cmp0xff Date: Tue, 16 Dec 2025 22:31:26 +0100 Subject: [PATCH] enable reportUnknownArgumentType --- pandas-stubs/core/dtypes/missing.pyi | 3 ++- pandas-stubs/errors/__init__.pyi | 1 + pyproject.toml | 1 - tests/__init__.py | 14 ++++++----- tests/extension/decimal/array.py | 10 +++++--- tests/frame/test_frame.py | 6 ++--- tests/frame/test_groupby.py | 2 +- tests/indexes/test_indexes.py | 8 ++++++- tests/scalars/test_scalars.py | 2 +- tests/series/test_series.py | 36 +++++----------------------- tests/test_api_typing.py | 2 +- tests/test_io.py | 26 ++++++++++++++++---- tests/test_natype.py | 2 +- tests/test_pandas.py | 7 +++--- tests/test_plotting.py | 16 ++----------- tests/test_resampler.py | 2 +- tests/test_timefuncs.py | 4 ++-- 17 files changed, 68 insertions(+), 74 deletions(-) diff --git a/pandas-stubs/core/dtypes/missing.pyi b/pandas-stubs/core/dtypes/missing.pyi index dad3e5c2e..bd1a4924c 100644 --- a/pandas-stubs/core/dtypes/missing.pyi +++ b/pandas-stubs/core/dtypes/missing.pyi @@ -17,6 +17,7 @@ from pandas._libs.tslibs import NaTType from pandas._typing import ( Scalar, ScalarT, + ScalarT0, ShapeT, np_1darray_bool, np_ndarray, @@ -54,6 +55,6 @@ def notna(obj: np_ndarray[ShapeT]) -> np_ndarray[ShapeT, np.bool]: ... @overload def notna(obj: list[Any]) -> np_ndarray_bool: ... @overload -def notna(obj: ScalarT | NaTType | NAType | None) -> TypeIs[ScalarT]: ... +def notna(obj: ScalarT0 | NaTType | NAType | None) -> TypeIs[ScalarT0]: ... notnull = notna diff --git a/pandas-stubs/errors/__init__.pyi b/pandas-stubs/errors/__init__.pyi index 0b2d13369..542ca4e95 100644 --- a/pandas-stubs/errors/__init__.pyi +++ b/pandas-stubs/errors/__init__.pyi @@ -48,3 +48,4 @@ class InvalidColumnName(Warning): ... class CategoricalConversionWarning(Warning): ... class InvalidVersion(ValueError): ... class NoBufferPresent(Exception): ... +class Pandas4Warning(Warning): ... diff --git a/pyproject.toml b/pyproject.toml index 5bbb39c53..8cde1e444 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -299,7 +299,6 @@ enableTypeIgnoreComments = false # use pyright-specific ignores # disable subset of strict reportMissingParameterType = false reportUnnecessaryTypeIgnoreComment = true -reportUnknownArgumentType = false reportUnknownLambdaType = false reportUnknownMemberType = false reportUnknownParameterType = false diff --git a/tests/__init__.py b/tests/__init__.py index 6653740a7..60548280f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,6 @@ from __future__ import annotations +from collections.abc import Iterable from contextlib import ( AbstractContextManager, nullcontext, @@ -11,6 +12,7 @@ Any, Final, Literal, + cast, get_args, get_origin, ) @@ -140,17 +142,17 @@ def check( elif isinstance(actual, pd.Index): value = actual[index_to_check_for_type] elif isinstance(actual, BaseGroupBy): - value = actual.obj # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue] - elif hasattr(actual, "__iter__"): - value = next( - iter(actual) # pyright: ignore[reportArgumentType,reportCallIssue] - ) + value = actual.obj # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue] + elif isinstance(actual, Iterable): + value = next(iter(cast("Iterable[Any]", actual))) else: assert hasattr(actual, attr) value = getattr(actual, attr) if not isinstance(value, dtype): - raise RuntimeError(f"Expected type '{dtype}' but got '{type(value)}'") + raise RuntimeError( + f"Expected type '{dtype}' but got '{type(value)}'" # pyright: ignore[reportUnknownArgumentType] + ) return actual diff --git a/tests/extension/decimal/array.py b/tests/extension/decimal/array.py index 9fcad7f50..7560b2867 100644 --- a/tests/extension/decimal/array.py +++ b/tests/extension/decimal/array.py @@ -35,6 +35,7 @@ from pandas._typing import ( ArrayLike, AstypeArg, + Dtype, ListLike, ScalarIndexer, SequenceIndexer, @@ -199,8 +200,11 @@ def reconstruct( return DecimalArray._from_sequence(x) if ufunc.nout > 1: - return tuple(reconstruct(x) for x in result) - return reconstruct(result) + return tuple( + reconstruct(x) # pyright: ignore[reportUnknownArgumentType] + for x in result + ) + return reconstruct(result) # pyright: ignore[reportUnknownArgumentType] def __getitem__(self, item: ScalarIndexer | SequenceIndexer) -> Any: if isinstance(item, numbers.Integral): @@ -241,7 +245,7 @@ def astype(self, dtype: ExtensionDtype, copy: bool = True) -> ExtensionArray: .. @overload def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike: ... - def astype(self, dtype, copy=True): + def astype(self, dtype: Dtype, copy: bool = True): if is_dtype_equal(dtype, self._dtype): if not copy: return self diff --git a/tests/frame/test_frame.py b/tests/frame/test_frame.py index c72148337..df90ad3ed 100644 --- a/tests/frame/test_frame.py +++ b/tests/frame/test_frame.py @@ -1,3 +1,4 @@ +# pyright: reportUnknownArgumentType=false from __future__ import annotations from collections import ( @@ -76,7 +77,7 @@ _PandasNamedTuple: TypeAlias = tuple if not PD_LTE_23: - from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip + from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration] else: Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] @@ -2315,8 +2316,7 @@ def test_types_rename_axis() -> None: check( assert_type( df.rename_axis( - index=lambda name: name.upper(), - columns=lambda name: name.upper(), + index=lambda name: name.upper(), columns=lambda name: name.upper() ), pd.DataFrame, ), diff --git a/tests/frame/test_groupby.py b/tests/frame/test_groupby.py index 2f39e870f..5a7dd3abc 100644 --- a/tests/frame/test_groupby.py +++ b/tests/frame/test_groupby.py @@ -123,7 +123,7 @@ def test_types_groupby() -> None: # GH 284 df.groupby(df["col1"] > 2) df.groupby([df["col1"] > 2, df["col2"] % 2 == 1]) - df.groupby(lambda x: x) + df.groupby(lambda x: x) # pyright: ignore[reportUnknownArgumentType] df.groupby([lambda x: x % 2, lambda x: x % 3]) df.groupby(np.array([1, 0, 1])) df.groupby([np.array([1, 0, 0]), np.array([0, 0, 1])]) diff --git a/tests/indexes/test_indexes.py b/tests/indexes/test_indexes.py index 601e803d2..e8e843209 100644 --- a/tests/indexes/test_indexes.py +++ b/tests/indexes/test_indexes.py @@ -1719,7 +1719,13 @@ def test_index_view() -> None: # - pyright: ndarray[tuple[Any, ...], dtype[Any]] check(assert_type(ind.view(np.ndarray), np.ndarray), np.ndarray) # type: ignore[assert-type] else: - check(assert_type(ind.view(np.ndarray), np.ndarray[Any, Any]), np.ndarray) + check( + assert_type( + ind.view(np.ndarray), # pyright: ignore[reportUnknownArgumentType] + np.ndarray[Any, Any], + ), + np.ndarray, + ) if sys.version_info >= (3, 11): diff --git a/tests/scalars/test_scalars.py b/tests/scalars/test_scalars.py index fc441af48..8e449cb7a 100644 --- a/tests/scalars/test_scalars.py +++ b/tests/scalars/test_scalars.py @@ -41,7 +41,7 @@ ) if not PD_LTE_23: - from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip + from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration] else: Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] diff --git a/tests/series/test_series.py b/tests/series/test_series.py index 2dfadd624..d6edc36f4 100644 --- a/tests/series/test_series.py +++ b/tests/series/test_series.py @@ -1,3 +1,4 @@ +# pyright: reportUnknownArgumentType=false from __future__ import annotations from collections.abc import ( @@ -102,7 +103,7 @@ ) if not PD_LTE_23: - from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip + from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration] else: Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] @@ -1160,20 +1161,8 @@ def transform_func( pd.Series, float, ) - check( - assert_type( - s.groupby(lambda x: x).transform("mean"), - "pd.Series", - ), - pd.Series, - ) - check( - assert_type( - s.groupby(lambda x: x).transform("first"), - "pd.Series", - ), - pd.Series, - ) + check(assert_type(s.groupby(lambda x: x).transform("mean"), pd.Series), pd.Series) + check(assert_type(s.groupby(lambda x: x).transform("first"), pd.Series), pd.Series) def test_types_groupby_aggregate() -> None: @@ -3254,11 +3243,7 @@ def first_arg_series( check( assert_type( ser.pipe( - first_arg_series, - 1, - [1.0, 2.0], - argument_2="hi", - keyword_only=(1, 2), + first_arg_series, 1, [1.0, 2.0], argument_2="hi", keyword_only=(1, 2) ), pd.Series, ), @@ -3319,16 +3304,7 @@ def first_arg_series( def first_arg_not_series(argument_1: int, ser: pd.Series) -> pd.Series: return ser - check( - assert_type( - ser.pipe( - (first_arg_not_series, "ser"), - 1, - ), - pd.Series, - ), - pd.Series, - ) + check(assert_type(ser.pipe((first_arg_not_series, "ser"), 1), pd.Series), pd.Series) if TYPE_CHECKING_INVALID_USAGE: ser.pipe( diff --git a/tests/test_api_typing.py b/tests/test_api_typing.py index 4c5f0a038..bbdbb51f9 100644 --- a/tests/test_api_typing.py +++ b/tests/test_api_typing.py @@ -1,4 +1,4 @@ -# pyright: reportMissingTypeArgument=false +# pyright: reportMissingTypeArgument=false, reportUnknownArgumentType=false """Test module for classes in pandas.api.typing.""" from typing import TypeAlias diff --git a/tests/test_io.py b/tests/test_io.py index ecf4cfd8a..bbed901c6 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -1159,7 +1159,12 @@ def test_excel_reader() -> None: def test_excel_writer() -> None: with ensure_clean(".xlsx") as path: with pd.ExcelWriter(path) as ew: - check(assert_type(ew, pd.ExcelWriter), pd.ExcelWriter) + check( + assert_type( + ew, pd.ExcelWriter # pyright: ignore[reportUnknownArgumentType] + ), + pd.ExcelWriter, + ) DF.to_excel(ew, sheet_name="A") check(assert_type(read_excel(path, sheet_name="A"), DataFrame), DataFrame) check(assert_type(read_excel(path), DataFrame), DataFrame) @@ -1188,7 +1193,13 @@ def test_excel_writer_io() -> None: def test_excel_writer_engine() -> None: with ensure_clean(".xlsx") as path: with pd.ExcelWriter(path, engine="auto") as ew: - check(assert_type(ew, pd.ExcelWriter), pd.ExcelWriter) + check( + assert_type( + ew, + pd.ExcelWriter, # pyright: ignore[reportUnknownArgumentType] + ), + pd.ExcelWriter, + ) DF.to_excel(ew, sheet_name="A") with ensure_clean(".xlsx") as path: @@ -1206,7 +1217,12 @@ def test_excel_writer_engine() -> None: with ensure_clean(".ods") as path: with pd.ExcelWriter(path, engine="odf") as ew: check( - assert_type(ew, pd.ExcelWriter[OpenDocument]), + assert_type( + ew, + pd.ExcelWriter[ + OpenDocument + ], # pyright: ignore[reportUnknownArgumentType] + ), pd.ExcelWriter[OpenDocument], ) DF.to_excel(ew, sheet_name="A") @@ -1218,7 +1234,9 @@ def test_excel_writer_engine() -> None: with ensure_clean(".xlsx") as path: with pd.ExcelWriter(path, engine="xlsxwriter") as ew: check( - assert_type(ew, pd.ExcelWriter[XlsxWorkbook]), + assert_type( + ew, pd.ExcelWriter[XlsxWorkbook] + ), # pyright: ignore[reportUnknownArgumentType] pd.ExcelWriter[XlsxWorkbook], ) DF.to_excel(ew, sheet_name="A") diff --git a/tests/test_natype.py b/tests/test_natype.py index 7a524bc37..a640f209c 100644 --- a/tests/test_natype.py +++ b/tests/test_natype.py @@ -98,7 +98,7 @@ def test_arithmetic() -> None: # ) # https://github.com/microsoft/pyright/issues/10899. check( - assert_type( + assert_type( # pyright: ignore[reportUnknownArgumentType] divmod( # pyright: ignore[reportCallIssue, reportAssertTypeFailure] na, 1 # pyright: ignore[reportArgumentType] ), diff --git a/tests/test_pandas.py b/tests/test_pandas.py index c3d237eb9..bf16d902f 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -285,8 +285,7 @@ def test_concat_series_mixed_numeric() -> None: ) check( assert_type( - pd.concat([s, s2], keys=["first", "second"], names=None), - pd.Series, + pd.concat([s, s2], keys=["first", "second"], names=None), pd.Series ), pd.Series, np.floating, @@ -527,7 +526,7 @@ def test_isna() -> None: if not pd.notna(nullable1): assert_type(nullable1, NaTType | NAType | None) - nullable2: int | None = random.choice([2, None]) + nullable2 = random.choice([2, None]) if pd.notna(nullable2): check(assert_type(nullable2, int), int) if not pd.isna(nullable2): @@ -1965,7 +1964,7 @@ def f(x: pd.Series) -> float: ) def g(x: pd.Series) -> int: - return int(np.round(x.sum())) + return int(np.round(x.sum())) # pyright: ignore[reportUnknownArgumentType] check( assert_type( diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 888c8f758..cb8eae93c 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -470,20 +470,8 @@ def test_plot_barh(close_figures: None) -> None: def test_plot_box(close_figures: None) -> None: check(assert_type(IRIS_DF.plot.box(), Axes), Axes) check(assert_type(IRIS_DF.plot(kind="box"), Axes), Axes) - check( - assert_type( - IRIS_DF.plot.box(subplots=True), - pd.Series, - ), - pd.Series, - ) - check( - assert_type( - IRIS_DF.plot(kind="box", subplots=True), - pd.Series, - ), - pd.Series, - ) + check(assert_type(IRIS_DF.plot.box(subplots=True), pd.Series), pd.Series) + check(assert_type(IRIS_DF.plot(kind="box", subplots=True), pd.Series), pd.Series) def test_plot_density(close_figures: None) -> None: diff --git a/tests/test_resampler.py b/tests/test_resampler.py index 7bb43cac1..121cce83c 100644 --- a/tests/test_resampler.py +++ b/tests/test_resampler.py @@ -24,7 +24,7 @@ ) if not PD_LTE_23: - from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip + from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration] else: Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 0b210feb2..669dc96ce 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -52,7 +52,7 @@ ) if not PD_LTE_23: - from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip + from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration] else: Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] @@ -1646,7 +1646,7 @@ def test_timedeltaseries_add_timestampseries() -> None: def test_timestamp_strptime_fails() -> None: if TYPE_CHECKING_INVALID_USAGE: assert_never( - pd.Timestamp.strptime( + pd.Timestamp.strptime( # pyright: ignore[reportUnknownArgumentType] "2023-02-16", # type: ignore[arg-type] # pyright: ignore[reportArgumentType] "%Y-%M-%D", # type: ignore[arg-type] # pyright: ignore[reportArgumentType] )