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: hooks:
- id: rst-backticks - id: rst-backticks
- repo: https://github.com/pre-commit/mirrors-mypy - repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.711 rev: v0.720
hooks: hooks:
- id: mypy - id: mypy
name: mypy (src) files: ^(src/|testing/)
files: ^src/
args: []
- id: mypy
name: mypy (testing)
files: ^testing/
args: [] args: []
- repo: local - repo: local
hooks: 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) :] text = text[len(self._striptext) :]
return text 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 True if the exception is an instance of exc """
return isinstance(self.value, exc) return isinstance(self.value, exc)

View File

@ -24,10 +24,7 @@ class OutcomeException(BaseException):
def __repr__(self) -> str: def __repr__(self) -> str:
if self.msg: if self.msg:
val = self.msg return self.msg
if isinstance(val, bytes):
val = val.decode("UTF-8", errors="replace")
return val
return "<{} instance>".format(self.__class__.__name__) return "<{} instance>".format(self.__class__.__name__)
__str__ = __repr__ __str__ = __repr__

View File

@ -1164,7 +1164,7 @@ def _idval(val, argname, idx, idfn, item, config):
return str(val) return str(val)
elif isinstance(val, REGEX_TYPE): elif isinstance(val, REGEX_TYPE):
return ascii_escaped(val.pattern) return ascii_escaped(val.pattern)
elif enum is not None and isinstance(val, enum.Enum): elif isinstance(val, enum.Enum):
return str(val) return str(val)
elif (inspect.isclass(val) or inspect.isfunction(val)) and hasattr(val, "__name__"): elif (inspect.isclass(val) or inspect.isfunction(val)) and hasattr(val, "__name__"):
return val.__name__ return val.__name__

View File

@ -278,10 +278,7 @@ class SetupState:
self._finalizers = {} self._finalizers = {}
def addfinalizer(self, finalizer, colitem): def addfinalizer(self, finalizer, colitem):
""" attach a finalizer to the given 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().
"""
assert colitem and not isinstance(colitem, tuple) assert colitem and not isinstance(colitem, tuple)
assert callable(finalizer) assert callable(finalizer)
# assert colitem in self.stack # some unit tests don't setup stack :/ # assert colitem in self.stack # some unit tests don't setup stack :/
@ -309,12 +306,9 @@ class SetupState:
def _teardown_with_finalization(self, colitem): def _teardown_with_finalization(self, colitem):
self._callfinalizers(colitem) self._callfinalizers(colitem)
if hasattr(colitem, "teardown"):
colitem.teardown() colitem.teardown()
for colitem in self._finalizers: for colitem in self._finalizers:
assert ( assert colitem in self.stack
colitem is None or colitem in self.stack or isinstance(colitem, tuple)
)
def teardown_all(self): def teardown_all(self):
while self.stack: while self.stack: