Skip to content

Commit 0e58307

Browse files
authored
TYP: Upgrade to mypy 0.920 (#44936)
1 parent 3a4821e commit 0e58307

File tree

13 files changed

+33
-29
lines changed

13 files changed

+33
-29
lines changed

doc/source/whatsnew/v1.4.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ If installed, we now require:
397397
+-----------------+-----------------+----------+---------+
398398
| pytest (dev) | 6.0 | | |
399399
+-----------------+-----------------+----------+---------+
400-
| mypy (dev) | 0.910 | | X |
400+
| mypy (dev) | 0.920 | | X |
401401
+-----------------+-----------------+----------+---------+
402402

403403
For `optional libraries <https://pandas.pydata.org/docs/getting_started/install.html>`_ the general recommendation is to use the latest version.

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies:
2424
- flake8-bugbear=21.3.2 # used by flake8, find likely bugs
2525
- flake8-comprehensions=3.1.0 # used by flake8, linting of unnecessary comprehensions
2626
- isort>=5.2.1 # check that imports are in the right order
27-
- mypy=0.910
27+
- mypy=0.920
2828
- pre-commit>=2.9.2
2929
- pycodestyle # used by flake8
3030
- pyupgrade

pandas/compat/pickle_compat.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ def __new__(cls) -> DataFrame: # type: ignore[misc]
194194
# our Unpickler sub-class to override methods and some dispatcher
195195
# functions for compat and uses a non-public class of the pickle module.
196196

197-
# error: Name 'pkl._Unpickler' is not defined
198-
class Unpickler(pkl._Unpickler): # type: ignore[name-defined]
197+
198+
class Unpickler(pkl._Unpickler):
199199
def find_class(self, module, name):
200200
# override superclass
201201
key = (module, name)
@@ -266,7 +266,8 @@ def load(fh, encoding: str | None = None, is_verbose: bool = False):
266266
up = Unpickler(fh, encoding=encoding)
267267
else:
268268
up = Unpickler(fh)
269-
up.is_verbose = is_verbose
269+
# "Unpickler" has no attribute "is_verbose" [attr-defined]
270+
up.is_verbose = is_verbose # type: ignore[attr-defined]
270271

271272
return up.load()
272273
except (ValueError, TypeError):

pandas/core/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,7 @@ def to_numpy(
527527
dtype='datetime64[ns]')
528528
"""
529529
if is_extension_array_dtype(self.dtype):
530-
# error: Too many arguments for "to_numpy" of "ExtensionArray"
531-
return self.array.to_numpy( # type: ignore[call-arg]
532-
dtype, copy=copy, na_value=na_value, **kwargs
533-
)
530+
return self.array.to_numpy(dtype, copy=copy, na_value=na_value, **kwargs)
534531
elif kwargs:
535532
bad_keys = list(kwargs.keys())[0]
536533
raise TypeError(

pandas/core/frame.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,8 +2634,7 @@ def to_stata(
26342634
# Specifying the version is only supported for UTF8 (118 or 119)
26352635
kwargs["version"] = version
26362636

2637-
# mypy: Too many arguments for "StataWriter"
2638-
writer = statawriter( # type: ignore[call-arg]
2637+
writer = statawriter(
26392638
path,
26402639
self,
26412640
convert_dates=convert_dates,

pandas/core/indexes/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,9 @@ def __new__(
443443
return Index._simple_new(data, name=name)
444444

445445
elif is_ea_or_datetimelike_dtype(data_dtype):
446-
klass = cls._dtype_to_subclass(data_dtype)
446+
# Argument 1 to "_dtype_to_subclass" of "Index" has incompatible type
447+
# "Optional[Any]"; expected "Union[dtype[Any], ExtensionDtype]" [arg-type]
448+
klass = cls._dtype_to_subclass(data_dtype) # type: ignore[arg-type]
447449
if klass is not Index:
448450
result = klass(data, copy=copy, name=name, **kwargs)
449451
if dtype is not None:

pandas/core/indexes/multi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ def __new__(
327327
result._set_levels(levels, copy=copy, validate=False)
328328
result._set_codes(codes, copy=copy, validate=False)
329329

330-
result._names = [None] * len(levels)
330+
# Incompatible types in assignment (expression has type "List[None]",
331+
# variable has type "FrozenList") [assignment]
332+
result._names = [None] * len(levels) # type: ignore[assignment]
331333
if names is not None:
332334
# handles name validation
333335
result._set_names(names)

pandas/core/window/rolling.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,10 @@ def _apply(
11271127
-------
11281128
y : type of input
11291129
"""
1130-
window = self._scipy_weight_generator(self.window, **kwargs)
1130+
# "None" not callable [misc]
1131+
window = self._scipy_weight_generator( # type: ignore[misc]
1132+
self.window, **kwargs
1133+
)
11311134
offset = (len(window) - 1) // 2 if self.center else 0
11321135

11331136
def homogeneous_func(values: np.ndarray):

pandas/io/common.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -714,12 +714,10 @@ def get_handle(
714714

715715
# BZ Compression
716716
elif compression == "bz2":
717-
handle = bz2.BZ2File(
718-
# Argument 1 to "BZ2File" has incompatible type "Union[str,
719-
# Union[IO[Any], RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper,
720-
# mmap]]"; expected "Union[Union[str, bytes, _PathLike[str],
721-
# _PathLike[bytes]], IO[bytes]]"
722-
handle, # type: ignore[arg-type]
717+
# No overload variant of "BZ2File" matches argument types
718+
# "Union[str, BaseBuffer]", "str", "Dict[str, Any]"
719+
handle = bz2.BZ2File( # type: ignore[call-overload]
720+
handle,
723721
mode=ioargs.mode,
724722
**compression_args,
725723
)

pandas/io/parsers/readers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,8 +1170,7 @@ def _make_engine(self, engine="c"):
11701170
raise ValueError(
11711171
f"Unknown engine: {engine} (valid options are {mapping.keys()})"
11721172
)
1173-
# error: Too many arguments for "ParserBase"
1174-
return mapping[engine](self.f, **self.options) # type: ignore[call-arg]
1173+
return mapping[engine](self.f, **self.options)
11751174

11761175
def _failover_to_python(self):
11771176
raise AbstractMethodError(self)

pandas/io/pytables.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3351,8 +3351,11 @@ def validate(self, other):
33513351
if sv != ov:
33523352

33533353
# show the error for the specific axes
3354-
for i, sax in enumerate(sv):
3355-
oax = ov[i]
3354+
# Argument 1 to "enumerate" has incompatible type
3355+
# "Optional[Any]"; expected "Iterable[Any]" [arg-type]
3356+
for i, sax in enumerate(sv): # type: ignore[arg-type]
3357+
# Value of type "Optional[Any]" is not indexable [index]
3358+
oax = ov[i] # type: ignore[index]
33563359
if sax != oax:
33573360
raise ValueError(
33583361
f"invalid combination of [{c}] on appending data "
@@ -3592,7 +3595,9 @@ def f(i, c):
35923595
# TODO: why kind_attr here?
35933596
values = getattr(table_attrs, f"{adj_name}_kind", None)
35943597
dtype = getattr(table_attrs, f"{adj_name}_dtype", None)
3595-
kind = _dtype_to_kind(dtype)
3598+
# Argument 1 to "_dtype_to_kind" has incompatible type
3599+
# "Optional[Any]"; expected "str" [arg-type]
3600+
kind = _dtype_to_kind(dtype) # type: ignore[arg-type]
35963601

35973602
md = self.read_metadata(c)
35983603
# TODO: figure out why these two versions of `meta` dont always match.

pandas/plotting/_matplotlib/core.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,9 +1671,7 @@ def blank_labeler(label, value):
16711671
if labels is not None:
16721672
blabels = [blank_labeler(left, value) for left, value in zip(labels, y)]
16731673
else:
1674-
# error: Incompatible types in assignment (expression has type "None",
1675-
# variable has type "List[Any]")
1676-
blabels = None # type: ignore[assignment]
1674+
blabels = None
16771675
results = ax.pie(y, labels=blabels, **kwds)
16781676

16791677
if kwds.get("autopct", None) is not None:

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ flake8==3.9.2
1212
flake8-bugbear==21.3.2
1313
flake8-comprehensions==3.1.0
1414
isort>=5.2.1
15-
mypy==0.910
15+
mypy==0.920
1616
pre-commit>=2.9.2
1717
pycodestyle
1818
pyupgrade

0 commit comments

Comments
 (0)