Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve mypy setup + a few minor type fixes and removals #5615

Merged
merged 7 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,10 @@ repos:
hooks:
- id: rst-backticks
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.711
rev: v0.720
hooks:
- id: mypy
name: mypy (src)
files: ^src/
args: []
- id: mypy
name: mypy (testing)
files: ^testing/
files: ^(src/|testing/)
args: []
- repo: local
hooks:
Expand Down
7 changes: 7 additions & 0 deletions changelog/5615.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
``pytest.fail``, ``pytest.xfail`` and ``pytest.skip`` no longer support bytes for the message argument.

This was supported for Python 2 where it was tempting to use ``"message"``
instead of ``u"message"``.

Python 3 code is unlikely to pass ``bytes`` to these functions. If you do,
please decode it to an ``str`` beforehand.
4 changes: 3 additions & 1 deletion src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,9 @@ def exconly(self, tryshort: bool = False) -> str:
text = text[len(self._striptext) :]
return text

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

Expand Down
5 changes: 1 addition & 4 deletions src/_pytest/outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ def __init__(self, msg: Optional[str] = None, pytrace: bool = True) -> None:

def __repr__(self) -> str:
if self.msg:
val = self.msg
if isinstance(val, bytes):
val = val.decode("UTF-8", errors="replace")
return val
return self.msg
return "<{} instance>".format(self.__class__.__name__)

__str__ = __repr__
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ def _idval(val, argname, idx, idfn, item, config):
return str(val)
elif isinstance(val, REGEX_TYPE):
return ascii_escaped(val.pattern)
elif enum is not None and isinstance(val, enum.Enum):
elif isinstance(val, enum.Enum):
return str(val)
elif (inspect.isclass(val) or inspect.isfunction(val)) and hasattr(val, "__name__"):
return val.__name__
Expand Down
12 changes: 3 additions & 9 deletions src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,7 @@ def __init__(self):
self._finalizers = {}

def addfinalizer(self, finalizer, colitem):
""" attach a finalizer to the given colitem.
if colitem is None, this will add a finalizer that
is called at the end of teardown_all().
"""
""" attach a finalizer to the given colitem. """
RonnyPfannschmidt marked this conversation as resolved.
Show resolved Hide resolved
assert colitem and not isinstance(colitem, tuple)
assert callable(finalizer)
# assert colitem in self.stack # some unit tests don't setup stack :/
Expand Down Expand Up @@ -309,12 +306,9 @@ def _callfinalizers(self, colitem):

def _teardown_with_finalization(self, colitem):
self._callfinalizers(colitem)
if hasattr(colitem, "teardown"):
colitem.teardown()
colitem.teardown()
bluetech marked this conversation as resolved.
Show resolved Hide resolved
for colitem in self._finalizers:
assert (
colitem is None or colitem in self.stack or isinstance(colitem, tuple)
)
assert colitem in self.stack

def teardown_all(self):
while self.stack:
Expand Down