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 all commits
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=0.800
- pre-commit>=2.9.2
- pycodestyle # used by flake8
- pyupgrade
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ def stringify_path(
# this function with convert_file_like=True to infer the compression.
return cast(FileOrBuffer[AnyStr], filepath_or_buffer)

# Only @runtime_checkable protocols can be used with instance and class checks
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
8 changes: 3 additions & 5 deletions pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2489,11 +2489,9 @@ def write_file(self) -> None:
self._close()
except Exception as exc:
self.handles.close()
# Only @runtime_checkable protocols can be used with instance and class
# 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: 1 addition & 3 deletions pandas/tests/io/parser/common/test_file_buffer_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,7 @@ def test_read_csv_file_handle(all_parsers, io_class, encoding):
expected = DataFrame({"a": [1], "b": [2]})

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

tm.assert_frame_equal(parser.read_csv(handle, encoding=encoding), expected)
assert not handle.closed
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
5 changes: 3 additions & 2 deletions pandas/util/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def wrapper(*args, **kwargs) -> Callable[..., Any]:

{dedent(doc)}"""
)

return wrapper
# 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

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==0.800
pre-commit>=2.9.2
pycodestyle
pyupgrade
Expand Down