Skip to content

TYP: Make mypy 0.800 compatible #39407

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 2 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.790
- mypy
Copy link
Contributor

Choose a reason for hiding this comment

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

i think ok to pin >=

Copy link
Member

Choose a reason for hiding this comment

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

we have been pinning to exact version up to now.

we pin to avoid ci surprises. also since we use warn_unused_ignores = True, mypy will only be green with the specified version.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thx, pinned again

- pre-commit>=2.9.2
- pycodestyle # used by flake8
- pyupgrade
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def stringify_path(
return cast(FileOrBuffer[AnyStr], filepath_or_buffer)

# Only @runtime_checkable protocols can be used with instance and class checks
Copy link
Member

Choose a reason for hiding this comment

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

can remove this

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

if isinstance(filepath_or_buffer, os.PathLike): # type: ignore[misc]
if isinstance(filepath_or_buffer, os.PathLike):
filepath_or_buffer = filepath_or_buffer.__fspath__()
return _expand_user(filepath_or_buffer)

Expand Down
6 changes: 3 additions & 3 deletions pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2491,9 +2491,9 @@ def write_file(self) -> None:
self.handles.close()
# Only @runtime_checkable protocols can be used with instance and class
Copy link
Member

Choose a reason for hiding this comment

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

same

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

# checks
if isinstance(
self._fname, (str, os.PathLike) # type: ignore[misc]
) and os.path.isfile(self._fname):
if isinstance(self._fname, (str, os.PathLike)) and os.path.isfile(
self._fname
):
try:
os.unlink(self._fname)
except OSError:
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BoxPlot(LinePlot):

_valid_return_types = (None, "axes", "dict", "both")
# namedtuple to hold results
BP = namedtuple("Boxplot", ["ax", "lines"])
BP = namedtuple("BP", ["ax", "lines"])
Copy link
Contributor

Choose a reason for hiding this comment

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

OT we could use data classes here


def __init__(self, data, return_type="axes", **kwargs):
# Do not call LinePlot.__init__ which may fill nan
Expand Down
10 changes: 1 addition & 9 deletions pandas/tests/arrays/string_/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@


@pytest.fixture(
params=[
# pandas\tests\arrays\string_\test_string.py:16: error: List item 1 has
# incompatible type "ParameterSet"; expected
# "Sequence[Collection[object]]" [list-item]
"string",
pytest.param(
"arrow_string", marks=skip_if_no_pyarrow
), # type:ignore[list-item]
]
params=["string", pytest.param("arrow_string", marks=skip_if_no_pyarrow)]
)
def dtype(request):
return request.param
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class MockFile:
assert not is_file(data)


test_tuple = collections.namedtuple("Test", ["a", "b", "c"])
test_tuple = collections.namedtuple("test_tuple", ["a", "b", "c"])


@pytest.mark.parametrize("ll", [test_tuple(1, 2, 3)])
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/io/parser/common/test_file_buffer_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from io import BytesIO, StringIO
import os
import platform
from typing import Union
from urllib.error import URLError

import pytest
Expand Down Expand Up @@ -330,8 +331,9 @@ def test_read_csv_file_handle(all_parsers, io_class, encoding):
parser = all_parsers
expected = DataFrame({"a": [1], "b": [2]})

content = "a,b\n1,2"
content: Union[str, bytes] = "a,b\n1,2"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
content: Union[str, bytes] = "a,b\n1,2"
content: str | bytes = "a,b\n1,2"

😁

we have

[mypy-pandas.tests.*]
check_untyped_defs=False

so not sure why mypy is checking this function anyway.

OTOH could refactor...

    content = "a,b\n1,2"
    handle = io_class(content.encode("utf-8") if io_class == BytesIO else content)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm the refactor is better. Thx.

if io_class == BytesIO:
assert not isinstance(content, bytes)
content = content.encode("utf-8")
handle = io_class(content)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/parser/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_header_multi_index_invalid(all_parsers, kwargs, msg):
parser.read_csv(StringIO(data), header=[0, 1, 2, 3], **kwargs)


_TestTuple = namedtuple("names", ["first", "second"])
_TestTuple = namedtuple("_TestTuple", ["first", "second"])


@pytest.mark.parametrize(
Expand Down
9 changes: 2 additions & 7 deletions pandas/tests/window/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,7 @@ def ignore_na(request):


@pytest.fixture(
params=[
pytest.param(
"numba", marks=td.skip_if_no("numba", "0.46.0")
), # type: ignore[list-item]
"cython",
]
params=[pytest.param("numba", marks=td.skip_if_no("numba", "0.46.0")), "cython"]
)
def engine(request):
"""engine keyword argument for rolling.apply"""
Expand Down Expand Up @@ -332,7 +327,7 @@ def halflife_with_times(request):
"float64",
"m8[ns]",
"M8[ns]",
pytest.param( # type: ignore[list-item]
pytest.param(
"datetime64[ns, UTC]",
marks=pytest.mark.skip(
"direct creation of extension dtype datetime64[ns, UTC] "
Expand Down
2 changes: 1 addition & 1 deletion pandas/util/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def wrapper(*args, **kwargs) -> Callable[..., Any]:
{dedent(doc)}"""
)

return wrapper
return wrapper # type: ignore[return-value]
Copy link
Member

Choose a reason for hiding this comment

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

add the error message as a comment to help future readers and contributors looking to help with #37715

Suggested change
return wrapper # type: ignore[return-value]
# error: Incompatible return value type (got "Callable[[VarArg(Any),
# KwArg(Any)], Callable[...,Any]]", expected "Callable[[F], F]")
return wrapper # type: ignore[return-value]

Copy link
Member Author

Choose a reason for hiding this comment

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

Done



def deprecate_kwarg(
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.790
mypy
pre-commit>=2.9.2
pycodestyle
pyupgrade
Expand Down