Skip to content

Commit 51b04e0

Browse files
authored
TYP: fix typing errors for mypy==0.790, bump mypy version (#37108)
1 parent f6a4f29 commit 51b04e0

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

doc/source/whatsnew/v1.3.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ If installed, we now require:
8888
+-----------------+-----------------+----------+---------+
8989
| pytest (dev) | 5.0.1 | | |
9090
+-----------------+-----------------+----------+---------+
91-
| mypy (dev) | 0.782 | | |
91+
| mypy (dev) | 0.790 | | X |
9292
+-----------------+-----------------+----------+---------+
9393

9494
For `optional libraries <https://dev.pandas.io/docs/install.html#dependencies>`_ the general recommendation is to use the latest version.

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies:
2323
- flake8
2424
- flake8-comprehensions>=3.1.0 # used by flake8, linting of unnecessary comprehensions
2525
- isort>=5.2.1 # check that imports are in the right order
26-
- mypy=0.782
26+
- mypy=0.790
2727
- pre-commit>=2.9.2
2828
- pycodestyle # used by flake8
2929
- pyupgrade

pandas/core/computation/parsing.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ def create_valid_python_identifier(name: str) -> str:
3838
# token.tok_name contains a readable description of the replacement string.
3939
special_characters_replacements = {
4040
char: f"_{token.tok_name[tokval]}_"
41-
# The ignore here is because of a bug in mypy that is resolved in 0.740
42-
for char, tokval in (
43-
tokenize.EXACT_TOKEN_TYPES.items() # type: ignore[attr-defined]
44-
)
41+
for char, tokval in (tokenize.EXACT_TOKEN_TYPES.items())
4542
}
4643
special_characters_replacements.update(
4744
{

pandas/core/groupby/ops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ def groups(self) -> Dict[Hashable, np.ndarray]:
283283
return self.groupings[0].groups
284284
else:
285285
to_groupby = zip(*(ping.grouper for ping in self.groupings))
286-
to_groupby = Index(to_groupby)
287-
return self.axis.groupby(to_groupby)
286+
index = Index(to_groupby)
287+
return self.axis.groupby(index)
288288

289289
@final
290290
@cache_readonly

pandas/io/common.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ def stringify_path(
179179
# this function with convert_file_like=True to infer the compression.
180180
return cast(FileOrBuffer[AnyStr], filepath_or_buffer)
181181

182-
if isinstance(filepath_or_buffer, os.PathLike):
182+
# Only @runtime_checkable protocols can be used with instance and class checks
183+
if isinstance(filepath_or_buffer, os.PathLike): # type: ignore[misc]
183184
filepath_or_buffer = filepath_or_buffer.__fspath__()
184185
return _expand_user(filepath_or_buffer)
185186

@@ -487,9 +488,15 @@ def infer_compression(
487488
if compression in _compression_to_extension:
488489
return compression
489490

490-
msg = f"Unrecognized compression type: {compression}"
491-
valid = ["infer", None] + sorted(_compression_to_extension)
492-
msg += f"\nValid compression types are {valid}"
491+
# https://github.com/python/mypy/issues/5492
492+
# Unsupported operand types for + ("List[Optional[str]]" and "List[str]")
493+
valid = ["infer", None] + sorted(
494+
_compression_to_extension
495+
) # type: ignore[operator]
496+
msg = (
497+
f"Unrecognized compression type: {compression}\n"
498+
f"Valid compression types are {valid}"
499+
)
493500
raise ValueError(msg)
494501

495502

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cpplint
1111
flake8
1212
flake8-comprehensions>=3.1.0
1313
isort>=5.2.1
14-
mypy==0.782
14+
mypy==0.790
1515
pre-commit>=2.9.2
1616
pycodestyle
1717
pyupgrade

0 commit comments

Comments
 (0)