diff --git a/environment.yml b/environment.yml index be6fb9a4cac7d..cac705bff72ea 100644 --- a/environment.yml +++ b/environment.yml @@ -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 diff --git a/pandas/io/common.py b/pandas/io/common.py index 57ae46a421fbb..f71522b5c9555 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -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) diff --git a/pandas/io/stata.py b/pandas/io/stata.py index 0f7137041710b..9a5c9e4a2e2b2 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -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: diff --git a/pandas/plotting/_matplotlib/boxplot.py b/pandas/plotting/_matplotlib/boxplot.py index c1f3b3ef36260..1fb75cd9d13e4 100644 --- a/pandas/plotting/_matplotlib/boxplot.py +++ b/pandas/plotting/_matplotlib/boxplot.py @@ -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"]) def __init__(self, data, return_type="axes", **kwargs): # Do not call LinePlot.__init__ which may fill nan diff --git a/pandas/tests/arrays/string_/test_string.py b/pandas/tests/arrays/string_/test_string.py index d14de990d8268..8c766b96ecb9a 100644 --- a/pandas/tests/arrays/string_/test_string.py +++ b/pandas/tests/arrays/string_/test_string.py @@ -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 diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index e1f339e360c77..415fe0309b073 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -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)]) diff --git a/pandas/tests/io/parser/common/test_file_buffer_url.py b/pandas/tests/io/parser/common/test_file_buffer_url.py index d0f1d63f88b3e..018f93f1eb06b 100644 --- a/pandas/tests/io/parser/common/test_file_buffer_url.py +++ b/pandas/tests/io/parser/common/test_file_buffer_url.py @@ -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 diff --git a/pandas/tests/io/parser/test_header.py b/pandas/tests/io/parser/test_header.py index ae2808f494118..0b8dc1900ebb4 100644 --- a/pandas/tests/io/parser/test_header.py +++ b/pandas/tests/io/parser/test_header.py @@ -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( diff --git a/pandas/tests/window/conftest.py b/pandas/tests/window/conftest.py index 70bead489d2c6..7ac033244fae7 100644 --- a/pandas/tests/window/conftest.py +++ b/pandas/tests/window/conftest.py @@ -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""" @@ -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] " diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index d002e8a4ebd43..a13fb1ce57f6c 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -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] def deprecate_kwarg( diff --git a/requirements-dev.txt b/requirements-dev.txt index 054c924daa81c..9bae344adc520 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -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