- Add 64_handl_embed_excep.patch fixing
gh#agronholm/exceptiongroup#64. OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-exceptiongroup?expand=0&rev=14
This commit is contained in:
parent
48c7731673
commit
75be636421
98
64_handl_embed_excep.patch
Normal file
98
64_handl_embed_excep.patch
Normal file
@ -0,0 +1,98 @@
|
||||
From 821d5ebaadfd0b5b16c785a942f69e89933217bf Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= <alex.gronholm@nextday.fi>
|
||||
Date: Mon, 3 Jul 2023 00:54:13 +0300
|
||||
Subject: [PATCH] Changed handling of a single exception raised in exception
|
||||
group handlers to match Python 3.11.4
|
||||
|
||||
Fixes #64.
|
||||
---
|
||||
CHANGES.rst | 6 ++++++
|
||||
src/exceptiongroup/_catch.py | 5 ++++-
|
||||
tests/test_catch.py | 8 +-------
|
||||
tests/test_catch_py311.py | 8 +-------
|
||||
4 files changed, 12 insertions(+), 15 deletions(-)
|
||||
|
||||
diff --git a/CHANGES.rst b/CHANGES.rst
|
||||
index 31831a3..3c2b08f 100644
|
||||
--- a/CHANGES.rst
|
||||
+++ b/CHANGES.rst
|
||||
@@ -3,6 +3,12 @@ Version history
|
||||
|
||||
This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
|
||||
|
||||
+**UNRELEASED**
|
||||
+
|
||||
+- Changed handling of exceptions in exception group handler callbacks to not wrap a
|
||||
+ single exception in an exception group, as per
|
||||
+ `CPython issue 103590 <https://github.com/python/cpython/issues/103590>`_
|
||||
+
|
||||
**1.1.1**
|
||||
|
||||
- Worked around
|
||||
diff --git a/src/exceptiongroup/_catch.py b/src/exceptiongroup/_catch.py
|
||||
index aa16d16..0be39b4 100644
|
||||
--- a/src/exceptiongroup/_catch.py
|
||||
+++ b/src/exceptiongroup/_catch.py
|
||||
@@ -37,7 +37,7 @@ def __exit__(
|
||||
|
||||
return False
|
||||
|
||||
- def handle_exception(self, exc: BaseException) -> BaseExceptionGroup | None:
|
||||
+ def handle_exception(self, exc: BaseException) -> BaseException | None:
|
||||
excgroup: BaseExceptionGroup | None
|
||||
if isinstance(exc, BaseExceptionGroup):
|
||||
excgroup = exc
|
||||
@@ -57,6 +57,9 @@ def handle_exception(self, exc: BaseException) -> BaseExceptionGroup | None:
|
||||
break
|
||||
|
||||
if new_exceptions:
|
||||
+ if len(new_exceptions) == 1:
|
||||
+ return new_exceptions[0]
|
||||
+
|
||||
if excgroup:
|
||||
new_exceptions.append(excgroup)
|
||||
|
||||
diff --git a/tests/test_catch.py b/tests/test_catch.py
|
||||
index bc520b9..0af2fa0 100644
|
||||
--- a/tests/test_catch.py
|
||||
+++ b/tests/test_catch.py
|
||||
@@ -148,15 +148,9 @@ def test_catch_handler_raises():
|
||||
def handler(exc):
|
||||
raise RuntimeError("new")
|
||||
|
||||
- try:
|
||||
+ with pytest.raises(RuntimeError, match="new"):
|
||||
with catch({(ValueError, ValueError): handler}):
|
||||
raise ExceptionGroup("booboo", [ValueError("bar")])
|
||||
- except ExceptionGroup as exc:
|
||||
- assert exc.message == ""
|
||||
- assert len(exc.exceptions) == 1
|
||||
- assert isinstance(exc.exceptions[0], RuntimeError)
|
||||
- else:
|
||||
- pytest.fail("Did not raise an ExceptionGroup")
|
||||
|
||||
|
||||
def test_catch_subclass():
|
||||
diff --git a/tests/test_catch_py311.py b/tests/test_catch_py311.py
|
||||
index cc161e7..4351be8 100644
|
||||
--- a/tests/test_catch_py311.py
|
||||
+++ b/tests/test_catch_py311.py
|
||||
@@ -122,17 +122,11 @@ def test_catch_full_match():
|
||||
|
||||
|
||||
def test_catch_handler_raises():
|
||||
- try:
|
||||
+ with pytest.raises(RuntimeError, match="new"):
|
||||
try:
|
||||
raise ExceptionGroup("booboo", [ValueError("bar")])
|
||||
except* ValueError:
|
||||
raise RuntimeError("new")
|
||||
- except ExceptionGroup as exc:
|
||||
- assert exc.message == ""
|
||||
- assert len(exc.exceptions) == 1
|
||||
- assert isinstance(exc.exceptions[0], RuntimeError)
|
||||
- else:
|
||||
- pytest.fail("Did not raise an ExceptionGroup")
|
||||
|
||||
|
||||
def test_catch_subclass():
|
@ -5,6 +5,8 @@ Tue Jul 4 22:32:27 UTC 2023 - Matej Cepl <mcepl@suse.com>
|
||||
- Changed handling of exceptions in exception group handler
|
||||
callbacks to not wrap a single exception in an exception
|
||||
group, as per CPython issue gh#python/cpython#103590.
|
||||
- Add 64_handl_embed_excep.patch fixing
|
||||
gh#agronholm/exceptiongroup#64.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Fri Apr 21 12:24:46 UTC 2023 - Dirk Müller <dmueller@suse.com>
|
||||
|
@ -35,6 +35,9 @@ Summary: Backport of PEP 654 (exception groups)
|
||||
License: MIT AND Python-2.0
|
||||
URL: https://github.com/agronholm/exceptiongroup
|
||||
Source: https://github.com/agronholm/exceptiongroup/archive/refs/tags/%{version}.tar.gz#/exceptiongroup-%{version}-gh.tar.gz
|
||||
# PATCH-FIX-UPSTREAM 64_handl_embed_excep.patch gh#agronholm/exceptiongroup#64 mcepl@suse.com
|
||||
# Changed handling of a single exception raised in exception
|
||||
Patch0: 64_handl_embed_excep.patch
|
||||
BuildRequires: %{python_module base >= 3.7}
|
||||
BuildRequires: %{python_module flit-scm}
|
||||
BuildRequires: %{python_module pip}
|
||||
@ -75,7 +78,7 @@ exception group classes are used instead, ``TracebackException`` is not monkey p
|
||||
and the exception hook won't be installed.
|
||||
|
||||
%prep
|
||||
%setup -q -n exceptiongroup-%{version}
|
||||
%autosetup -p1 -n exceptiongroup-%{version}
|
||||
|
||||
%if !%{with test}
|
||||
%build
|
||||
|
Loading…
x
Reference in New Issue
Block a user