Skip to content

Commit c05fcc8

Browse files
authored
Merge pull request #5615 from bluetech/type-annotations-2
Improve mypy setup + a few minor type fixes and removals
2 parents faf222f + 675e950 commit c05fcc8

File tree

6 files changed

+17
-22
lines changed

6 files changed

+17
-22
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,10 @@ repos:
4444
hooks:
4545
- id: rst-backticks
4646
- repo: https://github.com/pre-commit/mirrors-mypy
47-
rev: v0.711
47+
rev: v0.720
4848
hooks:
4949
- id: mypy
50-
name: mypy (src)
51-
files: ^src/
52-
args: []
53-
- id: mypy
54-
name: mypy (testing)
55-
files: ^testing/
50+
files: ^(src/|testing/)
5651
args: []
5752
- repo: local
5853
hooks:

changelog/5615.removal.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
``pytest.fail``, ``pytest.xfail`` and ``pytest.skip`` no longer support bytes for the message argument.
2+
3+
This was supported for Python 2 where it was tempting to use ``"message"``
4+
instead of ``u"message"``.
5+
6+
Python 3 code is unlikely to pass ``bytes`` to these functions. If you do,
7+
please decode it to an ``str`` beforehand.

src/_pytest/_code/code.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,9 @@ def exconly(self, tryshort: bool = False) -> str:
520520
text = text[len(self._striptext) :]
521521
return text
522522

523-
def errisinstance(self, exc: "Type[BaseException]") -> bool:
523+
def errisinstance(
524+
self, exc: Union["Type[BaseException]", Tuple["Type[BaseException]", ...]]
525+
) -> bool:
524526
""" return True if the exception is an instance of exc """
525527
return isinstance(self.value, exc)
526528

src/_pytest/outcomes.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ def __init__(self, msg: Optional[str] = None, pytrace: bool = True) -> None:
2424

2525
def __repr__(self) -> str:
2626
if self.msg:
27-
val = self.msg
28-
if isinstance(val, bytes):
29-
val = val.decode("UTF-8", errors="replace")
30-
return val
27+
return self.msg
3128
return "<{} instance>".format(self.__class__.__name__)
3229

3330
__str__ = __repr__

src/_pytest/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ def _idval(val, argname, idx, idfn, item, config):
11641164
return str(val)
11651165
elif isinstance(val, REGEX_TYPE):
11661166
return ascii_escaped(val.pattern)
1167-
elif enum is not None and isinstance(val, enum.Enum):
1167+
elif isinstance(val, enum.Enum):
11681168
return str(val)
11691169
elif (inspect.isclass(val) or inspect.isfunction(val)) and hasattr(val, "__name__"):
11701170
return val.__name__

src/_pytest/runner.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,7 @@ def __init__(self):
278278
self._finalizers = {}
279279

280280
def addfinalizer(self, finalizer, colitem):
281-
""" attach a finalizer to the given colitem.
282-
if colitem is None, this will add a finalizer that
283-
is called at the end of teardown_all().
284-
"""
281+
""" attach a finalizer to the given colitem. """
285282
assert colitem and not isinstance(colitem, tuple)
286283
assert callable(finalizer)
287284
# assert colitem in self.stack # some unit tests don't setup stack :/
@@ -309,12 +306,9 @@ def _callfinalizers(self, colitem):
309306

310307
def _teardown_with_finalization(self, colitem):
311308
self._callfinalizers(colitem)
312-
if hasattr(colitem, "teardown"):
313-
colitem.teardown()
309+
colitem.teardown()
314310
for colitem in self._finalizers:
315-
assert (
316-
colitem is None or colitem in self.stack or isinstance(colitem, tuple)
317-
)
311+
assert colitem in self.stack
318312

319313
def teardown_all(self):
320314
while self.stack:

0 commit comments

Comments
 (0)