diff --git a/loguru/_better_exceptions.py b/loguru/_better_exceptions.py index 481c245e..b05c77f2 100644 --- a/loguru/_better_exceptions.py +++ b/loguru/_better_exceptions.py @@ -16,9 +16,17 @@ def is_exception_group(exc): return isinstance(exc, ExceptionGroup) else: + try: + from exceptiongroup import ExceptionGroup + except ImportError: - def is_exception_group(exc): - return False + def is_exception_group(exc): + return False + + else: + + def is_exception_group(exc): + return isinstance(exc, ExceptionGroup) class SyntaxHighlighter: diff --git a/setup.py b/setup.py index 95563549..c37dc4e9 100644 --- a/setup.py +++ b/setup.py @@ -73,6 +73,7 @@ "colorama==0.4.6 ; python_version>='3.8'", "freezegun==1.1.0 ; python_version<'3.8'", "freezegun==1.2.2 ; python_version>='3.8'", + "exceptiongroup==1.1.3; ; pythonversion>='3.7' and python_version<'3.11'" # Type checking. "mypy==v0.910 ; python_version<'3.6'", "mypy==v0.971 ; python_version>='3.6' and python_version<'3.7'", diff --git a/tests/exceptions/output/modern/grouped_as_cause_and_context.txt b/tests/exceptions/output/modern/grouped_as_cause_and_context.txt index 2c0e1f03..b7b8dccd 100644 --- a/tests/exceptions/output/modern/grouped_as_cause_and_context.txt +++ b/tests/exceptions/output/modern/grouped_as_cause_and_context.txt @@ -1,20 +1,20 @@ + Exception Group Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 31, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 37, in main | raise ExceptionGroup("group_1", [error_1, error_2]) | ExceptionGroup: group_1 (2 sub-exceptions) +-+---------------- 1 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 20, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 26, in main | a() - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 10, in a + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 16, in a | 1 / 0 | ZeroDivisionError: division by zero +---------------- 2 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 25, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 31, in main | b() - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 14, in b + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 20, in b | raise ValueError("Error") | ValueError: Error +------------------------------------ @@ -22,21 +22,21 @@ The above exception was the direct cause of the following exception: + Exception Group Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 33, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 39, in main | raise ExceptionGroup("group_2", [error_2, error_1]) from err | ExceptionGroup: group_2 (2 sub-exceptions) +-+---------------- 1 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 25, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 31, in main | b() - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 14, in b + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 20, in b | raise ValueError("Error") | ValueError: Error +---------------- 2 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 20, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 26, in main | a() - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 10, in a + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 16, in a | 1 / 0 | ZeroDivisionError: division by zero +------------------------------------ @@ -44,35 +44,35 @@ The above exception was the direct cause of the following exception: During handling of the above exception, another exception occurred: + Exception Group Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 42, in + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 48, in | main() - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 35, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 41, in main | raise ExceptionGroup("group_3", [err]) | ExceptionGroup: group_3 (1 sub-exception) +-+---------------- 1 ---------------- | Exception Group Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 33, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 39, in main | raise ExceptionGroup("group_2", [error_2, error_1]) from err | ExceptionGroup: group_2 (2 sub-exceptions) +-+---------------- 1 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 25, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 31, in main | b() - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 14, in b + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 20, in b | raise ValueError("Error") | ValueError: Error +---------------- 2 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 20, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 26, in main | a() - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 10, in a + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 16, in a | 1 / 0 | ZeroDivisionError: division by zero +------------------------------------ + Exception Group Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 31, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 37, in main | raise ExceptionGroup("group_1", [error_1, error_2]) |  │ └ ValueError('Error') |  └ ZeroDivisionError('division by zero') @@ -81,22 +81,22 @@ During handling of the above exception, another exception occurred: +-+---------------- 1 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 20, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 26, in main | a() | └  | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 10, in a + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 16, in a | 1 / 0 | | ZeroDivisionError: division by zero +---------------- 2 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 25, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 31, in main | b() | └  | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 14, in b + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 20, in b | raise ValueError("Error") | | ValueError: Error @@ -108,7 +108,7 @@ During handling of the above exception, another exception occurred: + Exception Group Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 33, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 39, in main | raise ExceptionGroup("group_2", [error_2, error_1]) from err |  │ └ ZeroDivisionError('division by zero') |  └ ValueError('Error') @@ -117,22 +117,22 @@ During handling of the above exception, another exception occurred: +-+---------------- 1 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 25, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 31, in main | b() | └  | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 14, in b + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 20, in b | raise ValueError("Error") | | ValueError: Error +---------------- 2 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 20, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 26, in main | a() | └  | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 10, in a + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 16, in a | 1 / 0 | | ZeroDivisionError: division by zero @@ -144,18 +144,18 @@ During handling of the above exception, another exception occurred: + Exception Group Traceback (most recent call last): | - | > File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 42, in  + | > File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 48, in  | main() | └  | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 35, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 41, in main | raise ExceptionGroup("group_3", [err]) | | ExceptionGroup: group_3 (1 sub-exception) +-+---------------- 1 ---------------- | Exception Group Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 33, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 39, in main | raise ExceptionGroup("group_2", [error_2, error_1]) from err |  │ └ ZeroDivisionError('division by zero') |  └ ValueError('Error') @@ -164,22 +164,22 @@ During handling of the above exception, another exception occurred: +-+---------------- 1 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 25, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 31, in main | b() | └  | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 14, in b + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 20, in b | raise ValueError("Error") | | ValueError: Error +---------------- 2 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 20, in main + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 26, in main | a() | └  | - | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 10, in a + | File "tests/exceptions/source/modern/grouped_as_cause_and_context.py", line 16, in a | 1 / 0 | | ZeroDivisionError: division by zero diff --git a/tests/exceptions/output/modern/grouped_max_depth.txt b/tests/exceptions/output/modern/grouped_max_depth.txt index 91efffe9..a9933812 100644 --- a/tests/exceptions/output/modern/grouped_max_depth.txt +++ b/tests/exceptions/output/modern/grouped_max_depth.txt @@ -1,8 +1,8 @@ + Exception Group Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_max_depth.py", line 26, in + | File "tests/exceptions/source/modern/grouped_max_depth.py", line 31, in | main() - | File "tests/exceptions/source/modern/grouped_max_depth.py", line 19, in main + | File "tests/exceptions/source/modern/grouped_max_depth.py", line 24, in main | raise ExceptionGroup("group", [nesting_left, nesting_right, nesting_both]) | ExceptionGroup: group (3 sub-exceptions) +-+---------------- 1 ---------------- @@ -159,11 +159,11 @@ + Exception Group Traceback (most recent call last): | - | > File "tests/exceptions/source/modern/grouped_max_depth.py", line 26, in  + | > File "tests/exceptions/source/modern/grouped_max_depth.py", line 31, in  | main() | └  | - | File "tests/exceptions/source/modern/grouped_max_depth.py", line 19, in main + | File "tests/exceptions/source/modern/grouped_max_depth.py", line 24, in main | raise ExceptionGroup("group", [nesting_left, nesting_right, nesting_both]) |  │ │ └ ExceptionGroup('group', [ValueError(-99), ExceptionGroup('group', [ValueError(-98), ExceptionGroup('group', [ValueError(-97),... |  │ └ ExceptionGroup('group', [ExceptionGroup('group', [ExceptionGroup('group', [ExceptionGroup('group', [ExceptionGroup('group', [... diff --git a/tests/exceptions/output/modern/grouped_max_length.txt b/tests/exceptions/output/modern/grouped_max_length.txt index 43cc4efc..c7ed1463 100644 --- a/tests/exceptions/output/modern/grouped_max_length.txt +++ b/tests/exceptions/output/modern/grouped_max_length.txt @@ -1,8 +1,8 @@ + Exception Group Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_max_length.py", line 15, in + | File "tests/exceptions/source/modern/grouped_max_length.py", line 20, in | main() - | File "tests/exceptions/source/modern/grouped_max_length.py", line 8, in main + | File "tests/exceptions/source/modern/grouped_max_length.py", line 13, in main | raise ExceptionGroup("group", errors) | ExceptionGroup: group (100 sub-exceptions) +-+---------------- 1 ---------------- @@ -41,11 +41,11 @@ + Exception Group Traceback (most recent call last): | - | > File "tests/exceptions/source/modern/grouped_max_length.py", line 15, in  + | > File "tests/exceptions/source/modern/grouped_max_length.py", line 20, in  | main() | └  | - | File "tests/exceptions/source/modern/grouped_max_length.py", line 8, in main + | File "tests/exceptions/source/modern/grouped_max_length.py", line 13, in main | raise ExceptionGroup("group", errors) |  └ [ValueError(0), ValueError(1), ValueError(2), ValueError(3), ValueError(4), ValueError(5), ValueError(6), ValueError(7), Valu... | diff --git a/tests/exceptions/output/modern/grouped_nested.txt b/tests/exceptions/output/modern/grouped_nested.txt index 95036aeb..7f697f37 100644 --- a/tests/exceptions/output/modern/grouped_nested.txt +++ b/tests/exceptions/output/modern/grouped_nested.txt @@ -1,27 +1,27 @@ + Exception Group Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_nested.py", line 40, in + | File "tests/exceptions/source/modern/grouped_nested.py", line 45, in | main() - | File "tests/exceptions/source/modern/grouped_nested.py", line 33, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 38, in main | raise ExceptionGroup("group_2", [error_4, error_3]) from None | ExceptionGroup: group_2 (2 sub-exceptions) +-+---------------- 1 ---------------- | Exception Group Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_nested.py", line 26, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 31, in main | raise ExceptionGroup("group_1", [error_1, error_2]) | ExceptionGroup: group_1 (2 sub-exceptions) +-+---------------- 1 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_nested.py", line 17, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 22, in main | divide_by_zero() - | File "tests/exceptions/source/modern/grouped_nested.py", line 6, in divide_by_zero + | File "tests/exceptions/source/modern/grouped_nested.py", line 11, in divide_by_zero | 1 / 0 | ZeroDivisionError: division by zero +---------------- 2 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_nested.py", line 22, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 27, in main | raise_value_error(100) - | File "tests/exceptions/source/modern/grouped_nested.py", line 10, in raise_value_error + | File "tests/exceptions/source/modern/grouped_nested.py", line 15, in raise_value_error | raise ValueError(value) | ValueError: 100 +------------------------------------ @@ -29,39 +29,39 @@ | During handling of the above exception, another exception occurred: | | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_nested.py", line 29, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 34, in main | raise_value_error(-100) - | File "tests/exceptions/source/modern/grouped_nested.py", line 10, in raise_value_error + | File "tests/exceptions/source/modern/grouped_nested.py", line 15, in raise_value_error | raise ValueError(value) | ValueError: -100 +---------------- 2 ---------------- | Exception Group Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_nested.py", line 26, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 31, in main | raise ExceptionGroup("group_1", [error_1, error_2]) | ExceptionGroup: group_1 (2 sub-exceptions) +-+---------------- 1 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_nested.py", line 17, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 22, in main | divide_by_zero() - | File "tests/exceptions/source/modern/grouped_nested.py", line 6, in divide_by_zero + | File "tests/exceptions/source/modern/grouped_nested.py", line 11, in divide_by_zero | 1 / 0 | ZeroDivisionError: division by zero +---------------- 2 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_nested.py", line 22, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 27, in main | raise_value_error(100) - | File "tests/exceptions/source/modern/grouped_nested.py", line 10, in raise_value_error + | File "tests/exceptions/source/modern/grouped_nested.py", line 15, in raise_value_error | raise ValueError(value) | ValueError: 100 +------------------------------------ + Exception Group Traceback (most recent call last): | - | > File "tests/exceptions/source/modern/grouped_nested.py", line 40, in  + | > File "tests/exceptions/source/modern/grouped_nested.py", line 45, in  | main() | └  | - | File "tests/exceptions/source/modern/grouped_nested.py", line 33, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 38, in main | raise ExceptionGroup("group_2", [error_4, error_3]) from None |  └ ValueError(-100) | @@ -69,7 +69,7 @@ +-+---------------- 1 ---------------- | Exception Group Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_nested.py", line 26, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 31, in main | raise ExceptionGroup("group_1", [error_1, error_2]) |  │ └ ValueError(100) |  └ ZeroDivisionError('division by zero') @@ -78,22 +78,22 @@ +-+---------------- 1 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_nested.py", line 17, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 22, in main | divide_by_zero() | └  | - | File "tests/exceptions/source/modern/grouped_nested.py", line 6, in divide_by_zero + | File "tests/exceptions/source/modern/grouped_nested.py", line 11, in divide_by_zero | 1 / 0 | | ZeroDivisionError: division by zero +---------------- 2 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_nested.py", line 22, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 27, in main | raise_value_error(100) | └  | - | File "tests/exceptions/source/modern/grouped_nested.py", line 10, in raise_value_error + | File "tests/exceptions/source/modern/grouped_nested.py", line 15, in raise_value_error | raise ValueError(value) |  └ 100 | @@ -106,11 +106,11 @@ | | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_nested.py", line 29, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 34, in main | raise_value_error(-100) | └  | - | File "tests/exceptions/source/modern/grouped_nested.py", line 10, in raise_value_error + | File "tests/exceptions/source/modern/grouped_nested.py", line 15, in raise_value_error | raise ValueError(value) |  └ -100 | @@ -118,7 +118,7 @@ +---------------- 2 ---------------- | Exception Group Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_nested.py", line 26, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 31, in main | raise ExceptionGroup("group_1", [error_1, error_2]) |  │ └ ValueError(100) |  └ ZeroDivisionError('division by zero') @@ -127,22 +127,22 @@ +-+---------------- 1 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_nested.py", line 17, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 22, in main | divide_by_zero() | └  | - | File "tests/exceptions/source/modern/grouped_nested.py", line 6, in divide_by_zero + | File "tests/exceptions/source/modern/grouped_nested.py", line 11, in divide_by_zero | 1 / 0 | | ZeroDivisionError: division by zero +---------------- 2 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_nested.py", line 22, in main + | File "tests/exceptions/source/modern/grouped_nested.py", line 27, in main | raise_value_error(100) | └  | - | File "tests/exceptions/source/modern/grouped_nested.py", line 10, in raise_value_error + | File "tests/exceptions/source/modern/grouped_nested.py", line 15, in raise_value_error | raise ValueError(value) |  └ 100 | diff --git a/tests/exceptions/output/modern/grouped_simple.txt b/tests/exceptions/output/modern/grouped_simple.txt index b9915cb1..58be52eb 100644 --- a/tests/exceptions/output/modern/grouped_simple.txt +++ b/tests/exceptions/output/modern/grouped_simple.txt @@ -1,66 +1,66 @@ + Exception Group Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_simple.py", line 41, in + | File "tests/exceptions/source/modern/grouped_simple.py", line 47, in | main() - | File "tests/exceptions/source/modern/grouped_simple.py", line 34, in main + | File "tests/exceptions/source/modern/grouped_simple.py", line 40, in main | raise ExceptionGroup("group", [error_1, error_2, error_3]) from None | ExceptionGroup: group (3 sub-exceptions) +-+---------------- 1 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_simple.py", line 26, in main + | File "tests/exceptions/source/modern/grouped_simple.py", line 32, in main | c(b) - | File "tests/exceptions/source/modern/grouped_simple.py", line 20, in c + | File "tests/exceptions/source/modern/grouped_simple.py", line 26, in c | f() - | File "tests/exceptions/source/modern/grouped_simple.py", line 16, in b + | File "tests/exceptions/source/modern/grouped_simple.py", line 22, in b | a() - | File "tests/exceptions/source/modern/grouped_simple.py", line 12, in a + | File "tests/exceptions/source/modern/grouped_simple.py", line 18, in a | x / y | ZeroDivisionError: division by zero +---------------- 2 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_simple.py", line 29, in main + | File "tests/exceptions/source/modern/grouped_simple.py", line 35, in main | c(a) - | File "tests/exceptions/source/modern/grouped_simple.py", line 20, in c + | File "tests/exceptions/source/modern/grouped_simple.py", line 26, in c | f() - | File "tests/exceptions/source/modern/grouped_simple.py", line 12, in a + | File "tests/exceptions/source/modern/grouped_simple.py", line 18, in a | x / y | ZeroDivisionError: division by zero +---------------- 3 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_simple.py", line 32, in main + | File "tests/exceptions/source/modern/grouped_simple.py", line 38, in main | a() - | File "tests/exceptions/source/modern/grouped_simple.py", line 12, in a + | File "tests/exceptions/source/modern/grouped_simple.py", line 18, in a | x / y | ZeroDivisionError: division by zero +------------------------------------ + Exception Group Traceback (most recent call last): | - | > File "tests/exceptions/source/modern/grouped_simple.py", line 41, in  + | > File "tests/exceptions/source/modern/grouped_simple.py", line 47, in  | main() | └  | - | File "tests/exceptions/source/modern/grouped_simple.py", line 34, in main + | File "tests/exceptions/source/modern/grouped_simple.py", line 40, in main | raise ExceptionGroup("group", [error_1, error_2, error_3]) from None | | ExceptionGroup: group (3 sub-exceptions) +-+---------------- 1 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_simple.py", line 26, in main + | File "tests/exceptions/source/modern/grouped_simple.py", line 32, in main | c(b) | │ └  | └  | - | File "tests/exceptions/source/modern/grouped_simple.py", line 20, in c + | File "tests/exceptions/source/modern/grouped_simple.py", line 26, in c | f() | └  | - | File "tests/exceptions/source/modern/grouped_simple.py", line 16, in b + | File "tests/exceptions/source/modern/grouped_simple.py", line 22, in b | a() | └  | - | File "tests/exceptions/source/modern/grouped_simple.py", line 12, in a + | File "tests/exceptions/source/modern/grouped_simple.py", line 18, in a | x / y | │ └ 0 | └ 1 @@ -69,16 +69,16 @@ +---------------- 2 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_simple.py", line 29, in main + | File "tests/exceptions/source/modern/grouped_simple.py", line 35, in main | c(a) | │ └  | └  | - | File "tests/exceptions/source/modern/grouped_simple.py", line 20, in c + | File "tests/exceptions/source/modern/grouped_simple.py", line 26, in c | f() | └  | - | File "tests/exceptions/source/modern/grouped_simple.py", line 12, in a + | File "tests/exceptions/source/modern/grouped_simple.py", line 18, in a | x / y | │ └ 0 | └ 1 @@ -87,11 +87,11 @@ +---------------- 3 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_simple.py", line 32, in main + | File "tests/exceptions/source/modern/grouped_simple.py", line 38, in main | a() | └  | - | File "tests/exceptions/source/modern/grouped_simple.py", line 12, in a + | File "tests/exceptions/source/modern/grouped_simple.py", line 18, in a | x / y | │ └ 0 | └ 1 diff --git a/tests/exceptions/output/modern/grouped_with_cause_and_context.txt b/tests/exceptions/output/modern/grouped_with_cause_and_context.txt index cd5de99e..9d4b73d4 100644 --- a/tests/exceptions/output/modern/grouped_with_cause_and_context.txt +++ b/tests/exceptions/output/modern/grouped_with_cause_and_context.txt @@ -1,63 +1,63 @@ Traceback (most recent call last): - File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 31, in main + File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 37, in main a() - File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 10, in a + File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 16, in a 1 / 0 ZeroDivisionError: division by zero The above exception was the direct cause of the following exception: Traceback (most recent call last): - File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 34, in main + File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 40, in main raise ValueError("Error") from err ValueError: Error During handling of the above exception, another exception occurred: + Exception Group Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 43, in + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 49, in | main() - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 36, in main + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 42, in main | raise ExceptionGroup("from_context", [from_context, from_cause]) | ExceptionGroup: from_context (2 sub-exceptions) +-+---------------- 1 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 17, in main + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 23, in main | a() - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 10, in a + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 16, in a | 1 / 0 | ZeroDivisionError: division by zero | | The above exception was the direct cause of the following exception: | | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 19, in main + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 25, in main | raise ValueError("ContextError") from err | ValueError: ContextError +---------------- 2 ---------------- | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 24, in main + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 30, in main | a() - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 10, in a + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 16, in a | 1 / 0 | ZeroDivisionError: division by zero | | During handling of the above exception, another exception occurred: | | Traceback (most recent call last): - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 26, in main + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 32, in main | raise ValueError("CauseError") | ValueError: CauseError +------------------------------------ Traceback (most recent call last): - File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 31, in main + File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 37, in main a() └  - File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 10, in a + File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 16, in a 1 / 0 ZeroDivisionError: division by zero @@ -68,7 +68,7 @@ During handling of the above exception, another exception occurred: Traceback (most recent call last): - File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 34, in main + File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 40, in main raise ValueError("Error") from err ValueError: Error @@ -79,11 +79,11 @@ During handling of the above exception, another exception occurred: + Exception Group Traceback (most recent call last): | - | > File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 43, in  + | > File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 49, in  | main() | └  | - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 36, in main + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 42, in main | raise ExceptionGroup("from_context", [from_context, from_cause]) |  │ └ ValueError('CauseError') |  └ ValueError('ContextError') @@ -92,11 +92,11 @@ During handling of the above exception, another exception occurred: +-+---------------- 1 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 17, in main + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 23, in main | a() | └  | - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 10, in a + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 16, in a | 1 / 0 | | ZeroDivisionError: division by zero @@ -107,18 +107,18 @@ During handling of the above exception, another exception occurred: | | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 19, in main + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 25, in main | raise ValueError("ContextError") from err | | ValueError: ContextError +---------------- 2 ---------------- | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 24, in main + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 30, in main | a() | └  | - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 10, in a + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 16, in a | 1 / 0 | | ZeroDivisionError: division by zero @@ -129,7 +129,7 @@ During handling of the above exception, another exception occurred: | | Traceback (most recent call last): | - | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 26, in main + | File "tests/exceptions/source/modern/grouped_with_cause_and_context.py", line 32, in main | raise ValueError("CauseError") | | ValueError: CauseError diff --git a/tests/exceptions/source/modern/grouped_as_cause_and_context.py b/tests/exceptions/source/modern/grouped_as_cause_and_context.py index 01bdcfbd..ddf269b9 100644 --- a/tests/exceptions/source/modern/grouped_as_cause_and_context.py +++ b/tests/exceptions/source/modern/grouped_as_cause_and_context.py @@ -2,6 +2,12 @@ from loguru import logger +try: + from exceptiongroup import ExceptionGroup +except ImportError: + pass + + logger.remove() logger.add(sys.stderr, format="", diagnose=True, backtrace=True, colorize=False) diff --git a/tests/exceptions/source/modern/grouped_max_depth.py b/tests/exceptions/source/modern/grouped_max_depth.py index 1eebefe6..d6ca60dd 100644 --- a/tests/exceptions/source/modern/grouped_max_depth.py +++ b/tests/exceptions/source/modern/grouped_max_depth.py @@ -1,6 +1,11 @@ from loguru import logger import sys +try: + from exceptiongroup import ExceptionGroup +except ImportError: + pass + @logger.catch def main(): diff --git a/tests/exceptions/source/modern/grouped_max_length.py b/tests/exceptions/source/modern/grouped_max_length.py index 5346668e..8465daf9 100644 --- a/tests/exceptions/source/modern/grouped_max_length.py +++ b/tests/exceptions/source/modern/grouped_max_length.py @@ -1,6 +1,11 @@ from loguru import logger import sys +try: + from exceptiongroup import ExceptionGroup +except ImportError: + pass + @logger.catch def main(): diff --git a/tests/exceptions/source/modern/grouped_nested.py b/tests/exceptions/source/modern/grouped_nested.py index fb58f3ce..6d641dc6 100644 --- a/tests/exceptions/source/modern/grouped_nested.py +++ b/tests/exceptions/source/modern/grouped_nested.py @@ -1,6 +1,11 @@ from loguru import logger import sys +try: + from exceptiongroup import ExceptionGroup +except ImportError: + pass + def divide_by_zero(): 1 / 0 diff --git a/tests/exceptions/source/modern/grouped_simple.py b/tests/exceptions/source/modern/grouped_simple.py index f68c7152..f0cd007b 100644 --- a/tests/exceptions/source/modern/grouped_simple.py +++ b/tests/exceptions/source/modern/grouped_simple.py @@ -2,6 +2,12 @@ from loguru import logger +try: + from exceptiongroup import ExceptionGroup +except ImportError: + pass + + logger.remove() logger.add(sys.stderr, format="", diagnose=True, backtrace=True, colorize=False) diff --git a/tests/exceptions/source/modern/grouped_with_cause_and_context.py b/tests/exceptions/source/modern/grouped_with_cause_and_context.py index b6181445..eac6de37 100644 --- a/tests/exceptions/source/modern/grouped_with_cause_and_context.py +++ b/tests/exceptions/source/modern/grouped_with_cause_and_context.py @@ -2,6 +2,12 @@ from loguru import logger +try: + from exceptiongroup import ExceptionGroup +except ImportError: + pass + + logger.remove() logger.add(sys.stderr, format="", diagnose=True, backtrace=True, colorize=False) diff --git a/tests/test_exceptions_formatting.py b/tests/test_exceptions_formatting.py index 2cd1c0a9..4601c407 100644 --- a/tests/test_exceptions_formatting.py +++ b/tests/test_exceptions_formatting.py @@ -235,12 +235,13 @@ def test_exception_others(filename): ("walrus_operator", (3, 8)), ("match_statement", (3, 10)), ("exception_group_catch", (3, 11)), - ("grouped_simple", (3, 11)), - ("grouped_nested", (3, 11)), - ("grouped_with_cause_and_context", (3, 11)), - ("grouped_as_cause_and_context", (3, 11)), - ("grouped_max_length", (3, 11)), - ("grouped_max_depth", (3, 11)), + # The "ExceptionGroup" is a 3.11 feature, but we install a backport library for tests. + ("grouped_simple", (3, 7)), + ("grouped_nested", (3, 7)), + ("grouped_with_cause_and_context", (3, 7)), + ("grouped_as_cause_and_context", (3, 7)), + ("grouped_max_length", (3, 7)), + ("grouped_max_depth", (3, 7)), ], ) def test_exception_modern(filename, minimum_python_version):