|
1 |
| -import inspect |
2 | 1 | import math
|
3 | 2 | import pprint
|
4 | 3 | from collections.abc import Iterable
|
5 | 4 | from collections.abc import Mapping
|
6 | 5 | from collections.abc import Sized
|
7 | 6 | from decimal import Decimal
|
8 |
| -from itertools import filterfalse |
9 | 7 | from numbers import Number
|
10 | 8 | from types import TracebackType
|
11 | 9 | from typing import Any
|
|
18 | 16 | from typing import TypeVar
|
19 | 17 | from typing import Union
|
20 | 18 |
|
21 |
| -from more_itertools.more import always_iterable |
22 |
| - |
23 | 19 | import _pytest._code
|
24 | 20 | from _pytest.compat import overload
|
25 | 21 | from _pytest.compat import STRING_TYPES
|
|
30 | 26 | from typing import Type
|
31 | 27 |
|
32 | 28 |
|
33 |
| -BASE_TYPE = (type, STRING_TYPES) |
34 |
| - |
35 |
| - |
36 | 29 | def _non_numeric_type_error(value, at: Optional[str]) -> TypeError:
|
37 | 30 | at_str = " at {}".format(at) if at else ""
|
38 | 31 | return TypeError(
|
@@ -680,11 +673,16 @@ def raises( # noqa: F811
|
680 | 673 | documentation for :ref:`the try statement <python:try>`.
|
681 | 674 | """
|
682 | 675 | __tracebackhide__ = True
|
683 |
| - for exc in filterfalse( |
684 |
| - inspect.isclass, always_iterable(expected_exception, BASE_TYPE) |
685 |
| - ): |
686 |
| - msg = "exceptions must be derived from BaseException, not %s" |
687 |
| - raise TypeError(msg % type(exc)) |
| 676 | + |
| 677 | + if isinstance(expected_exception, type): |
| 678 | + excepted_exceptions = (expected_exception,) # type: Tuple[Type[_E], ...] |
| 679 | + else: |
| 680 | + excepted_exceptions = expected_exception |
| 681 | + for exc in excepted_exceptions: |
| 682 | + if not isinstance(exc, type) or not issubclass(exc, BaseException): |
| 683 | + msg = "expected exception must be a BaseException type, not {}" |
| 684 | + not_a = exc.__name__ if isinstance(exc, type) else type(exc).__name__ |
| 685 | + raise TypeError(msg.format(not_a)) |
688 | 686 |
|
689 | 687 | message = "DID NOT RAISE {}".format(expected_exception)
|
690 | 688 |
|
|
0 commit comments