diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 1ca513e8f5e6a..eb17bb58eb738 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -298,7 +298,7 @@ If installed, we now require: +-----------------+-----------------+----------+---------+ | Package | Minimum Version | Required | Changed | +=================+=================+==========+=========+ -| mypy (dev) | 0.981 | | X | +| mypy (dev) | 0.990 | | X | +-----------------+-----------------+----------+---------+ | python-dateutil | 2.8.2 | X | X | +-----------------+-----------------+----------+---------+ diff --git a/environment.yml b/environment.yml index f6ef6367800bd..3c1df67782132 100644 --- a/environment.yml +++ b/environment.yml @@ -88,7 +88,7 @@ dependencies: - flake8=5.0.4 - flake8-bugbear=22.7.1 # used by flake8, find likely bugs - isort>=5.2.1 # check that imports are in the right order - - mypy=0.981 + - mypy=0.990 - pre-commit>=2.15.0 - pycodestyle # used by flake8 - pyupgrade diff --git a/pandas/_libs/tslibs/offsets.pyi b/pandas/_libs/tslibs/offsets.pyi index 44e7e983b4038..eacdf17b0b4d3 100644 --- a/pandas/_libs/tslibs/offsets.pyi +++ b/pandas/_libs/tslibs/offsets.pyi @@ -253,7 +253,8 @@ class CustomBusinessHour(BusinessHour): class CustomBusinessMonthEnd(_CustomBusinessMonth): ... class CustomBusinessMonthBegin(_CustomBusinessMonth): ... -class DateOffset(RelativeDeltaOffset): ... +class OffsetMeta(type): ... +class DateOffset(RelativeDeltaOffset, metaclass=OffsetMeta): ... BDay = BusinessDay BMonthEnd = BusinessMonthEnd diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 725043616eaa7..77ef3611b7587 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -414,7 +414,7 @@ def agg_dict_like(self) -> DataFrame | Series: axis: AxisInt = 0 if isinstance(obj, ABCSeries) else 1 result = concat( - {k: results[k] for k in keys_to_use}, # type: ignore[misc] + {k: results[k] for k in keys_to_use}, axis=axis, keys=keys_to_use, ) diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index a190817d0ccf6..a3c201b402b0f 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -1646,10 +1646,12 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs): class ExtensionArraySupportsAnyAll(ExtensionArray): - def any(self, *, skipna: bool = True) -> bool: + def any(self, *, skipna: bool = True) -> bool: # type: ignore[empty-body] + # error: Missing return statement pass - def all(self, *, skipna: bool = True) -> bool: + def all(self, *, skipna: bool = True) -> bool: # type: ignore[empty-body] + # error: Missing return statement pass diff --git a/pandas/core/base.py b/pandas/core/base.py index 3d06c1830cc53..4dbe755a20b0f 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -1107,9 +1107,9 @@ def _memory_usage(self, deep: bool = False) -> int: are not components of the array if deep=False or if used on PyPy """ if hasattr(self.array, "memory_usage"): - # https://github.com/python/mypy/issues/1424 - # error: "ExtensionArray" has no attribute "memory_usage" - return self.array.memory_usage(deep=deep) # type: ignore[attr-defined] + return self.array.memory_usage( # pyright: ignore[reportGeneralTypeIssues] + deep=deep, + ) v = self.array.nbytes if deep and is_object_dtype(self) and not PYPY: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 5654ba469d05a..d720039697c76 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5444,9 +5444,8 @@ def fillna( ) -> DataFrame | None: ... - # error: Signature of "fillna" incompatible with supertype "NDFrame" @doc(NDFrame.fillna, **_shared_doc_kwargs) - def fillna( # type: ignore[override] + def fillna( self, value: Hashable | Mapping | Series | DataFrame = None, *, @@ -5535,9 +5534,8 @@ def replace( ) -> None: ... - # error: Signature of "replace" incompatible with supertype "NDFrame" @doc(NDFrame.replace, **_shared_doc_kwargs) - def replace( # type: ignore[override] + def replace( self, to_replace=None, value=lib.no_default, @@ -6682,10 +6680,9 @@ def sort_values( ... # TODO: Just move the sort_values doc here. - # error: Signature of "sort_values" incompatible with supertype "NDFrame" @Substitution(**_shared_doc_kwargs) @Appender(NDFrame.sort_values.__doc__) - def sort_values( # type: ignore[override] + def sort_values( self, by: IndexLabel, *, @@ -9205,8 +9202,9 @@ def any( ) -> DataFrame | Series: ... + # error: Missing return statement @doc(NDFrame.any, **_shared_doc_kwargs) - def any( + def any( # type: ignore[empty-body] self, axis: Axis = 0, bool_only: bool | None = None, diff --git a/pandas/core/interchange/column.py b/pandas/core/interchange/column.py index 75d07d1c2f7f6..c8675faec440c 100644 --- a/pandas/core/interchange/column.py +++ b/pandas/core/interchange/column.py @@ -81,10 +81,11 @@ def __init__(self, column: pd.Series, allow_copy: bool = True) -> None: self._col = column self._allow_copy = allow_copy - def size(self) -> int: + def size(self) -> int: # type: ignore[override] """ Size of the column, in elements. """ + # error: Signature of "size" incompatible with supertype "Column" [override] return self._col.size @property diff --git a/pandas/core/series.py b/pandas/core/series.py index 44732b9060ff9..f5172827d6d5a 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1655,14 +1655,9 @@ def to_string( return result else: if hasattr(buf, "write"): - # error: Item "str" of "Union[str, PathLike[str], WriteBuffer - # [str]]" has no attribute "write" - buf.write(result) # type: ignore[union-attr] + buf.write(result) else: - # error: Argument 1 to "open" has incompatible type "Union[str, - # PathLike[str], WriteBuffer[str]]"; expected "Union[Union[str, - # bytes, PathLike[str], PathLike[bytes]], int]" - with open(buf, "w") as f: # type: ignore[arg-type] + with open(buf, "w") as f: f.write(result) return None @@ -4408,8 +4403,9 @@ def any( ) -> Series | bool: ... + # error: Missing return statement @doc(NDFrame.any, **_shared_doc_kwargs) - def any( + def any( # type: ignore[empty-body] self, axis: Axis = 0, bool_only: bool | None = None, @@ -5022,9 +5018,8 @@ def fillna( ) -> Series | None: ... - # error: Signature of "fillna" incompatible with supertype "NDFrame" @doc(NDFrame.fillna, **_shared_doc_kwargs) - def fillna( # type: ignore[override] + def fillna( self, value: Hashable | Mapping | Series | DataFrame = None, *, @@ -5097,14 +5092,13 @@ def replace( ) -> None: ... - # error: Signature of "replace" incompatible with supertype "NDFrame" @doc( NDFrame.replace, klass=_shared_doc_kwargs["klass"], inplace=_shared_doc_kwargs["inplace"], replace_iloc=_shared_doc_kwargs["replace_iloc"], ) - def replace( # type: ignore[override] + def replace( self, to_replace=None, value=lib.no_default, diff --git a/pandas/io/common.py b/pandas/io/common.py index 265de02dd5d6b..4dae46c8f39f6 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -1053,8 +1053,7 @@ def __getattr__(self, name: str): def readable(self) -> bool: if hasattr(self.buffer, "readable"): - # error: "BaseBuffer" has no attribute "readable" - return self.buffer.readable() # type: ignore[attr-defined] + return self.buffer.readable() return True def seekable(self) -> bool: @@ -1064,8 +1063,7 @@ def seekable(self) -> bool: def writable(self) -> bool: if hasattr(self.buffer, "writable"): - # error: "BaseBuffer" has no attribute "writable" - return self.buffer.writable() # type: ignore[attr-defined] + return self.buffer.writable() return True diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 84947c4cfa4fc..da6c1ad47d2dd 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1835,8 +1835,7 @@ def _load_backend(backend: str) -> types.ModuleType: # entry_points lost dict API ~ PY 3.10 # https://github.com/python/importlib_metadata/issues/298 if hasattr(eps, "select"): - # error: "Dict[str, Tuple[EntryPoint, ...]]" has no attribute "select" - entry = eps.select(group=key) # type: ignore[attr-defined] + entry = eps.select(group=key) # pyright: ignore[reportGeneralTypeIssues] else: entry = eps.get(key, ()) for entry_point in entry: diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index f18066769f214..8fef3a231a748 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -397,12 +397,8 @@ def decorator(decorated: F) -> F: if docstring is None: continue if hasattr(docstring, "_docstring_components"): - # error: Item "str" of "Union[str, Callable[..., Any]]" has no attribute - # "_docstring_components" - # error: Item "function" of "Union[str, Callable[..., Any]]" has no - # attribute "_docstring_components" docstring_components.extend( - docstring._docstring_components # type: ignore[union-attr] + docstring._docstring_components # pyright: ignore[reportGeneralTypeIssues] # noqa: E501 ) elif isinstance(docstring, str) or docstring.__doc__: docstring_components.append(docstring) diff --git a/requirements-dev.txt b/requirements-dev.txt index 5e98113625374..30ee35db05c50 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -67,7 +67,7 @@ cpplint flake8==5.0.4 flake8-bugbear==22.7.1 isort>=5.2.1 -mypy==0.981 +mypy==0.990 pre-commit>=2.15.0 pycodestyle pyupgrade