Merge pull request #7907 from bluetech/mypy-790
Update mypy 0.782 -> 0.790, iniconfig typing
This commit is contained in:
		
						commit
						f61d4ed9d5
					
				| 
						 | 
					@ -49,11 +49,13 @@ repos:
 | 
				
			||||||
    hooks:
 | 
					    hooks:
 | 
				
			||||||
    -   id: python-use-type-annotations
 | 
					    -   id: python-use-type-annotations
 | 
				
			||||||
-   repo: https://github.com/pre-commit/mirrors-mypy
 | 
					-   repo: https://github.com/pre-commit/mirrors-mypy
 | 
				
			||||||
    rev: v0.782  # NOTE: keep this in sync with setup.cfg.
 | 
					    rev: v0.790  # NOTE: keep this in sync with setup.cfg.
 | 
				
			||||||
    hooks:
 | 
					    hooks:
 | 
				
			||||||
    -   id: mypy
 | 
					    -   id: mypy
 | 
				
			||||||
        files: ^(src/|testing/)
 | 
					        files: ^(src/|testing/)
 | 
				
			||||||
        args: []
 | 
					        args: []
 | 
				
			||||||
 | 
					        additional_dependencies:
 | 
				
			||||||
 | 
					          - iniconfig>=1.1.0
 | 
				
			||||||
-   repo: local
 | 
					-   repo: local
 | 
				
			||||||
    hooks:
 | 
					    hooks:
 | 
				
			||||||
    -   id: rst
 | 
					    -   id: rst
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,7 +63,7 @@ console_scripts =
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[options.extras_require]
 | 
					[options.extras_require]
 | 
				
			||||||
checkqa-mypy =
 | 
					checkqa-mypy =
 | 
				
			||||||
    mypy==0.780
 | 
					    mypy==0.790
 | 
				
			||||||
testing =
 | 
					testing =
 | 
				
			||||||
    argcomplete
 | 
					    argcomplete
 | 
				
			||||||
    hypothesis>=3.56
 | 
					    hypothesis>=3.56
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -382,7 +382,7 @@ class NFPlugin:
 | 
				
			||||||
            self.cached_nodeids.update(item.nodeid for item in items)
 | 
					            self.cached_nodeids.update(item.nodeid for item in items)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _get_increasing_order(self, items: Iterable[nodes.Item]) -> List[nodes.Item]:
 | 
					    def _get_increasing_order(self, items: Iterable[nodes.Item]) -> List[nodes.Item]:
 | 
				
			||||||
        return sorted(items, key=lambda item: item.fspath.mtime(), reverse=True)
 | 
					        return sorted(items, key=lambda item: item.fspath.mtime(), reverse=True)  # type: ignore[no-any-return]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def pytest_sessionfinish(self) -> None:
 | 
					    def pytest_sessionfinish(self) -> None:
 | 
				
			||||||
        config = self.config
 | 
					        config = self.config
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -380,8 +380,7 @@ class FDCaptureBinary:
 | 
				
			||||||
            self.syscapture = SysCapture(targetfd)
 | 
					            self.syscapture = SysCapture(targetfd)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            self.tmpfile = EncodedFile(
 | 
					            self.tmpfile = EncodedFile(
 | 
				
			||||||
                # TODO: Remove type ignore, fixed in next mypy release.
 | 
					                TemporaryFile(buffering=0),
 | 
				
			||||||
                TemporaryFile(buffering=0),  # type: ignore[arg-type]
 | 
					 | 
				
			||||||
                encoding="utf-8",
 | 
					                encoding="utf-8",
 | 
				
			||||||
                errors="replace",
 | 
					                errors="replace",
 | 
				
			||||||
                newline="",
 | 
					                newline="",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -150,9 +150,8 @@ def getfuncargnames(
 | 
				
			||||||
        p.name
 | 
					        p.name
 | 
				
			||||||
        for p in parameters.values()
 | 
					        for p in parameters.values()
 | 
				
			||||||
        if (
 | 
					        if (
 | 
				
			||||||
            # TODO: Remove type ignore after https://github.com/python/typeshed/pull/4383
 | 
					            p.kind is Parameter.POSITIONAL_OR_KEYWORD
 | 
				
			||||||
            p.kind is Parameter.POSITIONAL_OR_KEYWORD  # type: ignore[unreachable]
 | 
					            or p.kind is Parameter.KEYWORD_ONLY
 | 
				
			||||||
            or p.kind is Parameter.KEYWORD_ONLY  # type: ignore[unreachable]
 | 
					 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        and p.default is Parameter.empty
 | 
					        and p.default is Parameter.empty
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,7 +27,7 @@ def _parse_ini_config(path: Path) -> iniconfig.IniConfig:
 | 
				
			||||||
    Raise UsageError if the file cannot be parsed.
 | 
					    Raise UsageError if the file cannot be parsed.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        return iniconfig.IniConfig(path)
 | 
					        return iniconfig.IniConfig(str(path))
 | 
				
			||||||
    except iniconfig.ParseError as exc:
 | 
					    except iniconfig.ParseError as exc:
 | 
				
			||||||
        raise UsageError(str(exc)) from exc
 | 
					        raise UsageError(str(exc)) from exc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,6 +32,7 @@ from weakref import WeakKeyDictionary
 | 
				
			||||||
import attr
 | 
					import attr
 | 
				
			||||||
import py
 | 
					import py
 | 
				
			||||||
from iniconfig import IniConfig
 | 
					from iniconfig import IniConfig
 | 
				
			||||||
 | 
					from iniconfig import SectionWrapper
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
from _pytest import timing
 | 
					from _pytest import timing
 | 
				
			||||||
| 
						 | 
					@ -785,10 +786,10 @@ class Pytester:
 | 
				
			||||||
        """Write a tox.ini file with 'source' as contents."""
 | 
					        """Write a tox.ini file with 'source' as contents."""
 | 
				
			||||||
        return self.makefile(".ini", tox=source)
 | 
					        return self.makefile(".ini", tox=source)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def getinicfg(self, source: str) -> IniConfig:
 | 
					    def getinicfg(self, source: str) -> SectionWrapper:
 | 
				
			||||||
        """Return the pytest section from the tox.ini config file."""
 | 
					        """Return the pytest section from the tox.ini config file."""
 | 
				
			||||||
        p = self.makeini(source)
 | 
					        p = self.makeini(source)
 | 
				
			||||||
        return IniConfig(p)["pytest"]
 | 
					        return IniConfig(str(p))["pytest"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def makepyprojecttoml(self, source: str) -> Path:
 | 
					    def makepyprojecttoml(self, source: str) -> Path:
 | 
				
			||||||
        """Write a pyproject.toml file with 'source' as contents.
 | 
					        """Write a pyproject.toml file with 'source' as contents.
 | 
				
			||||||
| 
						 | 
					@ -1321,8 +1322,10 @@ class Pytester:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        __tracebackhide__ = True
 | 
					        __tracebackhide__ = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # TODO: Remove type ignore in next mypy release.
 | 
				
			||||||
 | 
					        #       https://github.com/python/typeshed/pull/4582
 | 
				
			||||||
        cmdargs = tuple(
 | 
					        cmdargs = tuple(
 | 
				
			||||||
            os.fspath(arg) if isinstance(arg, os.PathLike) else arg for arg in cmdargs
 | 
					            os.fspath(arg) if isinstance(arg, os.PathLike) else arg for arg in cmdargs  # type: ignore[misc]
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        p1 = self.path.joinpath("stdout")
 | 
					        p1 = self.path.joinpath("stdout")
 | 
				
			||||||
        p2 = self.path.joinpath("stderr")
 | 
					        p2 = self.path.joinpath("stderr")
 | 
				
			||||||
| 
						 | 
					@ -1541,9 +1544,9 @@ class Testdir:
 | 
				
			||||||
        """See :meth:`Pytester.makeini`."""
 | 
					        """See :meth:`Pytester.makeini`."""
 | 
				
			||||||
        return py.path.local(str(self._pytester.makeini(source)))
 | 
					        return py.path.local(str(self._pytester.makeini(source)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def getinicfg(self, source) -> py.path.local:
 | 
					    def getinicfg(self, source: str) -> SectionWrapper:
 | 
				
			||||||
        """See :meth:`Pytester.getinicfg`."""
 | 
					        """See :meth:`Pytester.getinicfg`."""
 | 
				
			||||||
        return py.path.local(str(self._pytester.getinicfg(source)))
 | 
					        return self._pytester.getinicfg(source)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def makepyprojecttoml(self, source) -> py.path.local:
 | 
					    def makepyprojecttoml(self, source) -> py.path.local:
 | 
				
			||||||
        """See :meth:`Pytester.makepyprojecttoml`."""
 | 
					        """See :meth:`Pytester.makepyprojecttoml`."""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -210,7 +210,7 @@ class ApproxScalar(ApproxBase):
 | 
				
			||||||
        # tolerances, i.e. non-numerics and infinities. Need to call abs to
 | 
					        # tolerances, i.e. non-numerics and infinities. Need to call abs to
 | 
				
			||||||
        # handle complex numbers, e.g. (inf + 1j).
 | 
					        # handle complex numbers, e.g. (inf + 1j).
 | 
				
			||||||
        if (not isinstance(self.expected, (Complex, Decimal))) or math.isinf(
 | 
					        if (not isinstance(self.expected, (Complex, Decimal))) or math.isinf(
 | 
				
			||||||
            abs(self.expected)
 | 
					            abs(self.expected)  # type: ignore[arg-type]
 | 
				
			||||||
        ):
 | 
					        ):
 | 
				
			||||||
            return str(self.expected)
 | 
					            return str(self.expected)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -253,8 +253,8 @@ class ApproxScalar(ApproxBase):
 | 
				
			||||||
        # Allow the user to control whether NaNs are considered equal to each
 | 
					        # Allow the user to control whether NaNs are considered equal to each
 | 
				
			||||||
        # other or not.  The abs() calls are for compatibility with complex
 | 
					        # other or not.  The abs() calls are for compatibility with complex
 | 
				
			||||||
        # numbers.
 | 
					        # numbers.
 | 
				
			||||||
        if math.isnan(abs(self.expected)):
 | 
					        if math.isnan(abs(self.expected)):  # type: ignore[arg-type]
 | 
				
			||||||
            return self.nan_ok and math.isnan(abs(actual))
 | 
					            return self.nan_ok and math.isnan(abs(actual))  # type: ignore[arg-type]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Infinity shouldn't be approximately equal to anything but itself, but
 | 
					        # Infinity shouldn't be approximately equal to anything but itself, but
 | 
				
			||||||
        # if there's a relative tolerance, it will be infinite and infinity
 | 
					        # if there's a relative tolerance, it will be infinite and infinity
 | 
				
			||||||
| 
						 | 
					@ -262,7 +262,7 @@ class ApproxScalar(ApproxBase):
 | 
				
			||||||
        # case would have been short circuited above, so here we can just
 | 
					        # case would have been short circuited above, so here we can just
 | 
				
			||||||
        # return false if the expected value is infinite.  The abs() call is
 | 
					        # return false if the expected value is infinite.  The abs() call is
 | 
				
			||||||
        # for compatibility with complex numbers.
 | 
					        # for compatibility with complex numbers.
 | 
				
			||||||
        if math.isinf(abs(self.expected)):
 | 
					        if math.isinf(abs(self.expected)):  # type: ignore[arg-type]
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Return true if the two numbers are within the tolerance.
 | 
					        # Return true if the two numbers are within the tolerance.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -77,8 +77,7 @@ def pytest_terminal_summary(terminalreporter: "TerminalReporter") -> None:
 | 
				
			||||||
                dlist.append(rep)
 | 
					                dlist.append(rep)
 | 
				
			||||||
    if not dlist:
 | 
					    if not dlist:
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    dlist.sort(key=lambda x: x.duration)
 | 
					    dlist.sort(key=lambda x: x.duration, reverse=True)  # type: ignore[no-any-return]
 | 
				
			||||||
    dlist.reverse()
 | 
					 | 
				
			||||||
    if not durations:
 | 
					    if not durations:
 | 
				
			||||||
        tr.write_sep("=", "slowest durations")
 | 
					        tr.write_sep("=", "slowest durations")
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1595,7 +1595,7 @@ class TestPyCacheDir:
 | 
				
			||||||
        if prefix:
 | 
					        if prefix:
 | 
				
			||||||
            if sys.version_info < (3, 8):
 | 
					            if sys.version_info < (3, 8):
 | 
				
			||||||
                pytest.skip("pycache_prefix not available in py<38")
 | 
					                pytest.skip("pycache_prefix not available in py<38")
 | 
				
			||||||
            monkeypatch.setattr(sys, "pycache_prefix", prefix)  # type:ignore
 | 
					            monkeypatch.setattr(sys, "pycache_prefix", prefix)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        assert get_cache_dir(Path(source)) == Path(expected)
 | 
					        assert get_cache_dir(Path(source)) == Path(expected)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1606,7 +1606,7 @@ def test_stderr_write_returns_len(capsys):
 | 
				
			||||||
def test_encodedfile_writelines(tmpfile: BinaryIO) -> None:
 | 
					def test_encodedfile_writelines(tmpfile: BinaryIO) -> None:
 | 
				
			||||||
    ef = capture.EncodedFile(tmpfile, encoding="utf-8")
 | 
					    ef = capture.EncodedFile(tmpfile, encoding="utf-8")
 | 
				
			||||||
    with pytest.raises(TypeError):
 | 
					    with pytest.raises(TypeError):
 | 
				
			||||||
        ef.writelines([b"line1", b"line2"])
 | 
					        ef.writelines([b"line1", b"line2"])  # type: ignore[list-item]
 | 
				
			||||||
    assert ef.writelines(["line3", "line4"]) is None  # type: ignore[func-returns-value]
 | 
					    assert ef.writelines(["line3", "line4"]) is None  # type: ignore[func-returns-value]
 | 
				
			||||||
    ef.flush()
 | 
					    ef.flush()
 | 
				
			||||||
    tmpfile.seek(0)
 | 
					    tmpfile.seek(0)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -886,14 +886,9 @@ class TestPDB:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestDebuggingBreakpoints:
 | 
					class TestDebuggingBreakpoints:
 | 
				
			||||||
    def test_supports_breakpoint_module_global(self):
 | 
					    def test_supports_breakpoint_module_global(self):
 | 
				
			||||||
        """
 | 
					        """Test that supports breakpoint global marks on Python 3.7+."""
 | 
				
			||||||
        Test that supports breakpoint global marks on Python 3.7+ and not on
 | 
					 | 
				
			||||||
        CPython 3.5, 2.7
 | 
					 | 
				
			||||||
        """
 | 
					 | 
				
			||||||
        if sys.version_info >= (3, 7):
 | 
					        if sys.version_info >= (3, 7):
 | 
				
			||||||
            assert SUPPORTS_BREAKPOINT_BUILTIN is True
 | 
					            assert SUPPORTS_BREAKPOINT_BUILTIN is True
 | 
				
			||||||
        if sys.version_info.major == 3 and sys.version_info.minor == 5:
 | 
					 | 
				
			||||||
            assert SUPPORTS_BREAKPOINT_BUILTIN is False  # type: ignore[comparison-overlap]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @pytest.mark.skipif(
 | 
					    @pytest.mark.skipif(
 | 
				
			||||||
        not SUPPORTS_BREAKPOINT_BUILTIN, reason="Requires breakpoint() builtin"
 | 
					        not SUPPORTS_BREAKPOINT_BUILTIN, reason="Requires breakpoint() builtin"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1049,7 +1049,7 @@ class TestLiterals:
 | 
				
			||||||
            ("1e3", "999"),
 | 
					            ("1e3", "999"),
 | 
				
			||||||
            # The current implementation doesn't understand that numbers inside
 | 
					            # The current implementation doesn't understand that numbers inside
 | 
				
			||||||
            # strings shouldn't be treated as numbers:
 | 
					            # strings shouldn't be treated as numbers:
 | 
				
			||||||
            pytest.param("'3.1416'", "'3.14'", marks=pytest.mark.xfail),  # type: ignore
 | 
					            pytest.param("'3.1416'", "'3.14'", marks=pytest.mark.xfail),
 | 
				
			||||||
        ],
 | 
					        ],
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    def test_number_non_matches(self, pytester, expression, output):
 | 
					    def test_number_non_matches(self, pytester, expression, output):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
 | 
					import io
 | 
				
			||||||
from typing import List
 | 
					from typing import List
 | 
				
			||||||
from typing import Union
 | 
					from typing import Union
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -95,7 +96,7 @@ class TestPaste:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def mocked(url, data):
 | 
					        def mocked(url, data):
 | 
				
			||||||
            calls.append((url, data))
 | 
					            calls.append((url, data))
 | 
				
			||||||
            raise urllib.error.HTTPError(url, 400, "Bad request", None, None)
 | 
					            raise urllib.error.HTTPError(url, 400, "Bad request", {}, io.BytesIO())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        monkeypatch.setattr(urllib.request, "urlopen", mocked)
 | 
					        monkeypatch.setattr(urllib.request, "urlopen", mocked)
 | 
				
			||||||
        return calls
 | 
					        return calls
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue