Skip to content

TYP: fix typing errors for mypy==0.790, bump mypy version #37108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 10, 2021
Merged
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ If installed, we now require:
+-----------------+-----------------+----------+---------+
| pytest (dev) | 5.0.1 | | |
+-----------------+-----------------+----------+---------+
| mypy (dev) | 0.782 | | |
| mypy (dev) | 0.790 | | X |
+-----------------+-----------------+----------+---------+

For `optional libraries <https://dev.pandas.io/docs/install.html#dependencies>`_ the general recommendation is to use the latest version.
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies:
- flake8
- flake8-comprehensions>=3.1.0 # used by flake8, linting of unnecessary comprehensions
- isort>=5.2.1 # check that imports are in the right order
- mypy=0.782
- mypy=0.790
- pre-commit>=2.9.2
- pycodestyle # used by flake8
- pyupgrade
Expand Down
5 changes: 1 addition & 4 deletions pandas/core/computation/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ def create_valid_python_identifier(name: str) -> str:
# token.tok_name contains a readable description of the replacement string.
special_characters_replacements = {
char: f"_{token.tok_name[tokval]}_"
# The ignore here is because of a bug in mypy that is resolved in 0.740
for char, tokval in (
tokenize.EXACT_TOKEN_TYPES.items() # type: ignore[attr-defined]
)
for char, tokval in (tokenize.EXACT_TOKEN_TYPES.items())
}
special_characters_replacements.update(
{
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ def groups(self) -> Dict[Hashable, np.ndarray]:
return self.groupings[0].groups
else:
to_groupby = zip(*(ping.grouper for ping in self.groupings))
to_groupby = Index(to_groupby)
return self.axis.groupby(to_groupby)
index = Index(to_groupby)
return self.axis.groupby(index)

@final
@cache_readonly
Expand Down
15 changes: 11 additions & 4 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ def stringify_path(
# this function with convert_file_like=True to infer the compression.
return cast(FileOrBuffer[AnyStr], filepath_or_buffer)

if isinstance(filepath_or_buffer, os.PathLike):
# Only @runtime_checkable protocols can be used with instance and class checks
if isinstance(filepath_or_buffer, os.PathLike): # type: ignore[misc]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filepath_or_buffer = filepath_or_buffer.__fspath__()
return _expand_user(filepath_or_buffer)

Expand Down Expand Up @@ -487,9 +488,15 @@ def infer_compression(
if compression in _compression_to_extension:
return compression

msg = f"Unrecognized compression type: {compression}"
valid = ["infer", None] + sorted(_compression_to_extension)
msg += f"\nValid compression types are {valid}"
# https://github.com/python/mypy/issues/5492
# Unsupported operand types for + ("List[Optional[str]]" and "List[str]")
valid = ["infer", None] + sorted(
_compression_to_extension
) # type: ignore[operator]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msg = (
f"Unrecognized compression type: {compression}\n"
f"Valid compression types are {valid}"
)
raise ValueError(msg)


Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cpplint
flake8
flake8-comprehensions>=3.1.0
isort>=5.2.1
mypy==0.782
mypy==0.790
pre-commit>=2.9.2
pycodestyle
pyupgrade
Expand Down