Skip to content

Commit 2c4c9f3

Browse files
authored
TYP: Make mypy 0.800 compatible (#39407)
1 parent ce3e57b commit 2c4c9f3

File tree

11 files changed

+16
-33
lines changed

11 files changed

+16
-33
lines changed

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.790
26+
- mypy=0.800
2727
- pre-commit>=2.9.2
2828
- pycodestyle # used by flake8
2929
- pyupgrade

pandas/io/common.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ def stringify_path(
181181
# this function with convert_file_like=True to infer the compression.
182182
return cast(FileOrBuffer[AnyStr], filepath_or_buffer)
183183

184-
# Only @runtime_checkable protocols can be used with instance and class checks
185-
if isinstance(filepath_or_buffer, os.PathLike): # type: ignore[misc]
184+
if isinstance(filepath_or_buffer, os.PathLike):
186185
filepath_or_buffer = filepath_or_buffer.__fspath__()
187186
return _expand_user(filepath_or_buffer)
188187

pandas/io/stata.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -2489,11 +2489,9 @@ def write_file(self) -> None:
24892489
self._close()
24902490
except Exception as exc:
24912491
self.handles.close()
2492-
# Only @runtime_checkable protocols can be used with instance and class
2493-
# checks
2494-
if isinstance(
2495-
self._fname, (str, os.PathLike) # type: ignore[misc]
2496-
) and os.path.isfile(self._fname):
2492+
if isinstance(self._fname, (str, os.PathLike)) and os.path.isfile(
2493+
self._fname
2494+
):
24972495
try:
24982496
os.unlink(self._fname)
24992497
except OSError:

pandas/plotting/_matplotlib/boxplot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class BoxPlot(LinePlot):
2828

2929
_valid_return_types = (None, "axes", "dict", "both")
3030
# namedtuple to hold results
31-
BP = namedtuple("Boxplot", ["ax", "lines"])
31+
BP = namedtuple("BP", ["ax", "lines"])
3232

3333
def __init__(self, data, return_type="axes", **kwargs):
3434
# Do not call LinePlot.__init__ which may fill nan

pandas/tests/arrays/string_/test_string.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@
1515

1616

1717
@pytest.fixture(
18-
params=[
19-
# pandas\tests\arrays\string_\test_string.py:16: error: List item 1 has
20-
# incompatible type "ParameterSet"; expected
21-
# "Sequence[Collection[object]]" [list-item]
22-
"string",
23-
pytest.param(
24-
"arrow_string", marks=skip_if_no_pyarrow
25-
), # type:ignore[list-item]
26-
]
18+
params=["string", pytest.param("arrow_string", marks=skip_if_no_pyarrow)]
2719
)
2820
def dtype(request):
2921
return request.param

pandas/tests/dtypes/test_inference.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class MockFile:
300300
assert not is_file(data)
301301

302302

303-
test_tuple = collections.namedtuple("Test", ["a", "b", "c"])
303+
test_tuple = collections.namedtuple("test_tuple", ["a", "b", "c"])
304304

305305

306306
@pytest.mark.parametrize("ll", [test_tuple(1, 2, 3)])

pandas/tests/io/parser/common/test_file_buffer_url.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,7 @@ def test_read_csv_file_handle(all_parsers, io_class, encoding):
331331
expected = DataFrame({"a": [1], "b": [2]})
332332

333333
content = "a,b\n1,2"
334-
if io_class == BytesIO:
335-
content = content.encode("utf-8")
336-
handle = io_class(content)
334+
handle = io_class(content.encode("utf-8") if io_class == BytesIO else content)
337335

338336
tm.assert_frame_equal(parser.read_csv(handle, encoding=encoding), expected)
339337
assert not handle.closed

pandas/tests/io/parser/test_header.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def test_header_multi_index_invalid(all_parsers, kwargs, msg):
181181
parser.read_csv(StringIO(data), header=[0, 1, 2, 3], **kwargs)
182182

183183

184-
_TestTuple = namedtuple("names", ["first", "second"])
184+
_TestTuple = namedtuple("_TestTuple", ["first", "second"])
185185

186186

187187
@pytest.mark.parametrize(

pandas/tests/window/conftest.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,7 @@ def ignore_na(request):
113113

114114

115115
@pytest.fixture(
116-
params=[
117-
pytest.param(
118-
"numba", marks=td.skip_if_no("numba", "0.46.0")
119-
), # type: ignore[list-item]
120-
"cython",
121-
]
116+
params=[pytest.param("numba", marks=td.skip_if_no("numba", "0.46.0")), "cython"]
122117
)
123118
def engine(request):
124119
"""engine keyword argument for rolling.apply"""
@@ -332,7 +327,7 @@ def halflife_with_times(request):
332327
"float64",
333328
"m8[ns]",
334329
"M8[ns]",
335-
pytest.param( # type: ignore[list-item]
330+
pytest.param(
336331
"datetime64[ns, UTC]",
337332
marks=pytest.mark.skip(
338333
"direct creation of extension dtype datetime64[ns, UTC] "

pandas/util/_decorators.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ def wrapper(*args, **kwargs) -> Callable[..., Any]:
7878
7979
{dedent(doc)}"""
8080
)
81-
82-
return wrapper
81+
# error: Incompatible return value type (got "Callable[[VarArg(Any),
82+
# KwArg(Any)], Callable[...,Any]]", expected "Callable[[F], F]")
83+
return wrapper # type: ignore[return-value]
8384

8485

8586
def deprecate_kwarg(

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.790
14+
mypy==0.800
1515
pre-commit>=2.9.2
1616
pycodestyle
1717
pyupgrade

0 commit comments

Comments
 (0)