Skip to content

Commit 747a1e6

Browse files
Thiago C. D'ÁvilaThiago C. D'Ávilanicoddemus
authored
Fix mypy errors (#194)
Co-authored-by: Thiago C. D'Ávila <[email protected]> Co-authored-by: Bruno Oliveira <[email protected]>
1 parent 449d3d0 commit 747a1e6

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ docs/_build/
5858

5959
# IDE
6060
.idea
61+
.vscode
6162
/src/pytest_mock/_version.py

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ repos:
1818
files: ^(CHANGELOG.rst|README.rst|HOWTORELEASE.rst|changelog/.*)$
1919
language: python
2020
additional_dependencies: [pygments, restructuredtext_lint]
21+
- repo: https://github.com/pre-commit/mirrors-mypy
22+
rev: v0.780 # NOTE: keep this in sync with tox.ini
23+
hooks:
24+
- id: mypy
25+
files: ^src
26+
args: []
27+
additional_dependencies: [pytest>=6]

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[mypy]
2+
pretty = True

src/pytest_mock/plugin.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
from typing import Any
2+
from typing import Dict
3+
14
import asyncio
25
import functools
36
import inspect
47

58
import pytest
69

7-
from ._version import version
8-
9-
__version__ = version
10-
1110

1211
def _get_mock_module(config):
1312
"""
@@ -209,7 +208,7 @@ def _mocker(pytestconfig):
209208

210209

211210
_mock_module_patches = []
212-
_mock_module_originals = {}
211+
_mock_module_originals = {} # type: Dict[str, Any]
213212

214213

215214
def assert_wrapper(__wrapped_mock_method__, *args, **kwargs):
@@ -228,18 +227,17 @@ def assert_wrapper(__wrapped_mock_method__, *args, **kwargs):
228227
introspection = ""
229228
try:
230229
assert actual_args == args[1:]
231-
except AssertionError as e:
232-
introspection += "\nArgs:\n" + str(e)
230+
except AssertionError as e_args:
231+
introspection += "\nArgs:\n" + str(e_args)
233232
try:
234233
assert actual_kwargs == kwargs
235-
except AssertionError as e:
236-
introspection += "\nKwargs:\n" + str(e)
237-
234+
except AssertionError as e_kwargs:
235+
introspection += "\nKwargs:\n" + str(e_kwargs)
238236
if introspection:
239237
msg += "\n\npytest introspection follows:\n" + introspection
240-
e = AssertionError(msg)
241-
e._mock_introspection_applied = True
242-
raise e
238+
e = AssertionError(msg)
239+
e._mock_introspection_applied = True
240+
raise e
243241

244242

245243
def wrap_assert_not_called(*args, **kwargs):

tox.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[tox]
2+
minversion = 3.5.3
23
envlist = py{35,36,37,38}, linting, norewrite
34

45
[testenv]
@@ -20,6 +21,11 @@ extras = dev
2021
basepython = python3.6
2122
commands = pre-commit run --all-files --show-diff-on-failure
2223

24+
[testenv:mypy]
25+
deps =
26+
mypy==0.780
27+
commands = mypy {posargs:src}
28+
2329
[pytest]
2430
addopts = -r a
2531

0 commit comments

Comments
 (0)