From 6bc636672513cf27cb37602976ef88cc12789935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Mon, 27 Dec 2021 13:14:23 -0500 Subject: [PATCH] TYP: mypy 0.930 and pyright 1.1.200 (#45067) --- .github/workflows/ci.yml | 2 +- .pre-commit-config.yaml | 2 +- doc/source/whatsnew/v1.4.0.rst | 2 +- environment.yml | 2 +- pandas/compat/chainmap.py | 12 ++++-------- pandas/core/arrays/_mixins.py | 10 ++-------- pandas/core/arrays/string_.py | 4 +--- pandas/core/arrays/string_arrow.py | 4 +--- pandas/core/computation/scope.py | 3 +-- pandas/core/indexes/frozen.py | 4 ++-- pandas/core/reshape/merge.py | 4 +--- pyproject.toml | 1 + requirements-dev.txt | 2 +- 13 files changed, 18 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9a85e25e60ef..d862fa1086f97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,7 +55,7 @@ jobs: - name: Install pyright # note: keep version in sync with .pre-commit-config.yaml - run: npm install -g pyright@1.1.171 + run: npm install -g pyright@1.1.200 - name: Build Pandas uses: ./.github/actions/build_pandas diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6ab940efaddd4..19a8a127fa1a5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -78,7 +78,7 @@ repos: types: [python] stages: [manual] # note: keep version in sync with .github/workflows/ci.yml - additional_dependencies: ['pyright@1.1.171'] + additional_dependencies: ['pyright@1.1.200'] - repo: local hooks: - id: flake8-rst diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index c069c1ce2413c..c74a2e1d993f9 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -398,7 +398,7 @@ If installed, we now require: +-----------------+-----------------+----------+---------+ | pytest (dev) | 6.0 | | | +-----------------+-----------------+----------+---------+ -| mypy (dev) | 0.920 | | X | +| mypy (dev) | 0.930 | | X | +-----------------+-----------------+----------+---------+ For `optional libraries `_ the general recommendation is to use the latest version. diff --git a/environment.yml b/environment.yml index ef6ec7352db05..15dd329f80deb 100644 --- a/environment.yml +++ b/environment.yml @@ -24,7 +24,7 @@ dependencies: - flake8-bugbear=21.3.2 # used by flake8, find likely bugs - flake8-comprehensions=3.7.0 # used by flake8, linting of unnecessary comprehensions - isort>=5.2.1 # check that imports are in the right order - - mypy=0.920 + - mypy=0.930 - pre-commit>=2.9.2 - pycodestyle # used by flake8 - pyupgrade diff --git a/pandas/compat/chainmap.py b/pandas/compat/chainmap.py index 035963e8255ea..9af7962fe4ad0 100644 --- a/pandas/compat/chainmap.py +++ b/pandas/compat/chainmap.py @@ -1,8 +1,6 @@ from typing import ( ChainMap, - MutableMapping, TypeVar, - cast, ) _KT = TypeVar("_KT") @@ -18,11 +16,10 @@ class DeepChainMap(ChainMap[_KT, _VT]): def __setitem__(self, key: _KT, value: _VT) -> None: for mapping in self.maps: - mutable_mapping = cast(MutableMapping[_KT, _VT], mapping) - if key in mutable_mapping: - mutable_mapping[key] = value + if key in mapping: + mapping[key] = value return - cast(MutableMapping[_KT, _VT], self.maps[0])[key] = value + self.maps[0][key] = value def __delitem__(self, key: _KT) -> None: """ @@ -32,8 +29,7 @@ def __delitem__(self, key: _KT) -> None: If `key` doesn't exist. """ for mapping in self.maps: - mutable_mapping = cast(MutableMapping[_KT, _VT], mapping) if key in mapping: - del mutable_mapping[key] + del mapping[key] return raise KeyError(key) diff --git a/pandas/core/arrays/_mixins.py b/pandas/core/arrays/_mixins.py index 1a876b05d2073..a40be5a988f26 100644 --- a/pandas/core/arrays/_mixins.py +++ b/pandas/core/arrays/_mixins.py @@ -138,13 +138,11 @@ def view(self, dtype: Dtype | None = None) -> ArrayLike: return TimedeltaArray(arr.view("i8"), dtype=dtype) - # error: Incompatible return value type (got "ndarray", expected - # "ExtensionArray") # error: Argument "dtype" to "view" of "_ArrayOrScalarCommon" has incompatible # type "Union[ExtensionDtype, dtype[Any]]"; expected "Union[dtype[Any], None, # type, _SupportsDType, str, Union[Tuple[Any, int], Tuple[Any, Union[int, # Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]]" - return arr.view(dtype=dtype) # type: ignore[return-value,arg-type] + return arr.view(dtype=dtype) # type: ignore[arg-type] def take( self: NDArrayBackedExtensionArrayT, @@ -276,13 +274,9 @@ def __getitem__( return self._box_func(result) return self._from_backing_data(result) - # error: Value of type variable "AnyArrayLike" of "extract_array" cannot be - # "Union[int, slice, ndarray]" # error: Incompatible types in assignment (expression has type "ExtensionArray", # variable has type "Union[int, slice, ndarray]") - key = extract_array( # type: ignore[type-var,assignment] - key, extract_numpy=True - ) + key = extract_array(key, extract_numpy=True) # type: ignore[assignment] key = check_array_indexer(self, key) result = self._ndarray[key] if lib.is_scalar(result): diff --git a/pandas/core/arrays/string_.py b/pandas/core/arrays/string_.py index c6987d9a11e4c..2bf8452903302 100644 --- a/pandas/core/arrays/string_.py +++ b/pandas/core/arrays/string_.py @@ -545,12 +545,10 @@ def _str_map( mask.view("uint8"), convert=False, na_value=na_value, - # error: Value of type variable "_DTypeScalar" of "dtype" cannot be - # "object" # error: Argument 1 to "dtype" has incompatible type # "Union[ExtensionDtype, str, dtype[Any], Type[object]]"; expected # "Type[object]" - dtype=np.dtype(dtype), # type: ignore[type-var,arg-type] + dtype=np.dtype(dtype), # type: ignore[arg-type] ) if not na_value_is_na: diff --git a/pandas/core/arrays/string_arrow.py b/pandas/core/arrays/string_arrow.py index 42dff27866d84..fb16834e5b4b2 100644 --- a/pandas/core/arrays/string_arrow.py +++ b/pandas/core/arrays/string_arrow.py @@ -675,12 +675,10 @@ def _str_map( mask.view("uint8"), convert=False, na_value=na_value, - # error: Value of type variable "_DTypeScalar" of "dtype" cannot be - # "object" # error: Argument 1 to "dtype" has incompatible type # "Union[ExtensionDtype, str, dtype[Any], Type[object]]"; expected # "Type[object]" - dtype=np.dtype(dtype), # type: ignore[type-var,arg-type] + dtype=np.dtype(dtype), # type: ignore[arg-type] ) if not na_value_is_na: diff --git a/pandas/core/computation/scope.py b/pandas/core/computation/scope.py index d4fbe226a3ae2..a561824f868f2 100644 --- a/pandas/core/computation/scope.py +++ b/pandas/core/computation/scope.py @@ -232,8 +232,7 @@ def swapkey(self, old_key: str, new_key: str, new_value=None) -> None: for mapping in maps: if old_key in mapping: - # error: Unsupported target for indexed assignment ("Mapping[Any, Any]") - mapping[new_key] = new_value # type: ignore[index] + mapping[new_key] = new_value return def _get_vars(self, stack, scopes: list[str]) -> None: diff --git a/pandas/core/indexes/frozen.py b/pandas/core/indexes/frozen.py index 3956dbaba5a68..ed5cf047ab59f 100644 --- a/pandas/core/indexes/frozen.py +++ b/pandas/core/indexes/frozen.py @@ -105,6 +105,6 @@ def __repr__(self) -> str: return f"{type(self).__name__}({str(self)})" __setitem__ = __setslice__ = _disabled # type: ignore[assignment] - __delitem__ = __delslice__ = _disabled # type: ignore[assignment] - pop = append = extend = _disabled # type: ignore[assignment] + __delitem__ = __delslice__ = _disabled + pop = append = extend = _disabled remove = sort = insert = _disabled # type: ignore[assignment] diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 960b8faec7c59..46b2e5d29d247 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -2154,11 +2154,9 @@ def _factorize_keys( # variable has type "ExtensionArray") lk, _ = lk._values_for_factorize() - # error: Incompatible types in assignment (expression has type - # "ndarray", variable has type "ExtensionArray") # error: Item "ndarray" of "Union[Any, ndarray]" has no attribute # "_values_for_factorize" - rk, _ = rk._values_for_factorize() # type: ignore[union-attr,assignment] + rk, _ = rk._values_for_factorize() # type: ignore[union-attr] klass: type[libhashtable.Factorizer] | type[libhashtable.Int64Factorizer] if is_integer_dtype(lk.dtype) and is_integer_dtype(rk.dtype): diff --git a/pyproject.toml b/pyproject.toml index 0c3e078d8761a..4455df705fc3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -159,6 +159,7 @@ reportImportCycles = false reportIncompatibleMethodOverride = false reportIncompatibleVariableOverride = false reportMissingModuleSource = false +reportMissingParameterType = false reportMissingTypeArgument = false reportMissingTypeStubs = false reportOptionalCall = false diff --git a/requirements-dev.txt b/requirements-dev.txt index 2f80440e71d16..f199d084371d9 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -12,7 +12,7 @@ flake8==4.0.1 flake8-bugbear==21.3.2 flake8-comprehensions==3.7.0 isort>=5.2.1 -mypy==0.920 +mypy==0.930 pre-commit>=2.9.2 pycodestyle pyupgrade