Update mypy 0.750 -> 0.761

This fixes some type: ignores due to typeshed update.

Newer mypy seem to ignore unannotated functions better, so add a few
minor annotations so that existing correct type:ignores make sense.
This commit is contained in:
Ran Benita 2020-01-01 14:49:59 +02:00
parent 466bbbf8e8
commit 4848bbdf9a
9 changed files with 12 additions and 18 deletions

View File

@ -37,7 +37,7 @@ repos:
- id: pyupgrade - id: pyupgrade
args: [--py3-plus] args: [--py3-plus]
- repo: https://github.com/pre-commit/mirrors-mypy - repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.750 rev: v0.761
hooks: hooks:
- id: mypy - id: mypy
files: ^(src/|testing/) files: ^(src/|testing/)

View File

@ -339,9 +339,7 @@ def getstatementrange_ast(
block_finder.started = source.lines[start][0].isspace() block_finder.started = source.lines[start][0].isspace()
it = ((x + "\n") for x in source.lines[start:end]) it = ((x + "\n") for x in source.lines[start:end])
try: try:
# Type ignored until next mypy release. for tok in tokenize.generate_tokens(lambda: next(it)):
# https://github.com/python/typeshed/commit/c0d46a20353b733befb85d8b9cc24e5b0bcd8f9a
for tok in tokenize.generate_tokens(lambda: next(it)): # type: ignore
block_finder.tokeneater(*tok) block_finder.tokeneater(*tok)
except (inspect.EndOfBlock, IndentationError): except (inspect.EndOfBlock, IndentationError):
end = block_finder.last + start end = block_finder.last + start

View File

@ -33,7 +33,7 @@ def pytest_addoption(parser):
) )
def register_assert_rewrite(*names): def register_assert_rewrite(*names) -> None:
"""Register one or more module names to be rewritten on import. """Register one or more module names to be rewritten on import.
This function will make sure that this module or all modules inside This function will make sure that this module or all modules inside

View File

@ -451,7 +451,9 @@ class DoctestModule(pytest.Module):
obj = getattr(obj, "fget", obj) obj = getattr(obj, "fget", obj)
return doctest.DocTestFinder._find_lineno(self, obj, source_lines) return doctest.DocTestFinder._find_lineno(self, obj, source_lines)
def _find(self, tests, obj, name, module, source_lines, globs, seen): def _find(
self, tests, obj, name, module, source_lines, globs, seen
) -> None:
if _is_mocked(obj): if _is_mocked(obj):
return return
with _patch_unwrap_mock_aware(): with _patch_unwrap_mock_aware():

View File

@ -829,7 +829,7 @@ class Testdir:
items = [x.item for x in rec.getcalls("pytest_itemcollected")] items = [x.item for x in rec.getcalls("pytest_itemcollected")]
return items, rec return items, rec
def inline_run(self, *args, plugins=(), no_reraise_ctrlc=False): def inline_run(self, *args, plugins=(), no_reraise_ctrlc: bool = False):
"""Run ``pytest.main()`` in-process, returning a HookRecorder. """Run ``pytest.main()`` in-process, returning a HookRecorder.
Runs the :py:func:`pytest.main` function to run all of pytest inside Runs the :py:func:`pytest.main` function to run all of pytest inside

View File

@ -129,9 +129,7 @@ def warns( # noqa: F811
return func(*args[1:], **kwargs) return func(*args[1:], **kwargs)
# Type ignored until next mypy release. Regression fixed by: class WarningsRecorder(warnings.catch_warnings):
# https://github.com/python/typeshed/commit/41bf6a19822d6694973449d795f8bfe1d50d5a03
class WarningsRecorder(warnings.catch_warnings): # type: ignore
"""A context manager to record raised warnings. """A context manager to record raised warnings.
Adapted from `warnings.catch_warnings`. Adapted from `warnings.catch_warnings`.

View File

@ -259,7 +259,7 @@ class TestReport(BaseReport):
) )
@classmethod @classmethod
def from_item_and_call(cls, item, call): def from_item_and_call(cls, item, call) -> "TestReport":
""" """
Factory method to create and fill a TestReport with standard item and call info. Factory method to create and fill a TestReport with standard item and call info.
""" """

View File

@ -250,7 +250,7 @@ def pytest_runtest_makereport(item, call):
return TestReport.from_item_and_call(item, call) return TestReport.from_item_and_call(item, call)
def pytest_make_collect_report(collector): def pytest_make_collect_report(collector) -> CollectReport:
call = CallInfo.from_call(lambda: list(collector.collect()), "collect") call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
longrepr = None longrepr = None
if not call.excinfo: if not call.excinfo:

View File

@ -318,16 +318,12 @@ class TestSourceParsingAndCompiling:
@pytest.mark.parametrize("name", ["", None, "my"]) @pytest.mark.parametrize("name", ["", None, "my"])
def test_compilefuncs_and_path_sanity(self, name: Optional[str]) -> None: def test_compilefuncs_and_path_sanity(self, name: Optional[str]) -> None:
def check(comp, name): def check(comp, name) -> None:
co = comp(self.source, name) co = comp(self.source, name)
if not name: if not name:
expected = "codegen %s:%d>" % (mypath, mylineno + 2 + 2) # type: ignore expected = "codegen %s:%d>" % (mypath, mylineno + 2 + 2) # type: ignore
else: else:
expected = "codegen %r %s:%d>" % ( expected = "codegen %r %s:%d>" % (name, mypath, mylineno + 2 + 2) # type: ignore
name,
mypath, # type: ignore
mylineno + 2 + 2, # type: ignore
) # type: ignore
fn = co.co_filename fn = co.co_filename
assert fn.endswith(expected) assert fn.endswith(expected)