Merge pull request #5615 from bluetech/type-annotations-2

Improve mypy setup + a few minor type fixes and removals
This commit is contained in:
Anthony Sottile 2019-07-19 06:48:24 -07:00 committed by GitHub
commit c05fcc8641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 22 deletions

View File

@ -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:

View File

@ -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.

View File

@ -520,7 +520,9 @@ class ExceptionInfo(Generic[_E]):
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)

View File

@ -24,10 +24,7 @@ class OutcomeException(BaseException):
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__

View File

@ -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__

View File

@ -278,10 +278,7 @@ class SetupState:
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. """
assert colitem and not isinstance(colitem, tuple)
assert callable(finalizer)
# assert colitem in self.stack # some unit tests don't setup stack :/
@ -309,12 +306,9 @@ class SetupState:
def _teardown_with_finalization(self, colitem):
self._callfinalizers(colitem)
if hasattr(colitem, "teardown"):
colitem.teardown()
colitem.teardown()
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: