mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-140530: fix a reference leak in an error path for raise exc from cause (#140908)
Fix a reference leak in `raise E from T` when `T` is an exception subtype for which `T.__new__` does not return an exception instance.
This commit is contained in:
parent
5ba0a1aa1f
commit
0c77e7c23b
3 changed files with 10 additions and 11 deletions
|
|
@ -186,18 +186,14 @@ def test_class_cause(self):
|
|||
self.fail("No exception raised")
|
||||
|
||||
def test_class_cause_nonexception_result(self):
|
||||
class ConstructsNone(BaseException):
|
||||
@classmethod
|
||||
# See https://github.com/python/cpython/issues/140530.
|
||||
class ConstructMortal(BaseException):
|
||||
def __new__(*args, **kwargs):
|
||||
return None
|
||||
try:
|
||||
raise IndexError from ConstructsNone
|
||||
except TypeError as e:
|
||||
self.assertIn("should have returned an instance of BaseException", str(e))
|
||||
except IndexError:
|
||||
self.fail("Wrong kind of exception raised")
|
||||
else:
|
||||
self.fail("No exception raised")
|
||||
return ["mortal value"]
|
||||
|
||||
msg = ".*should have returned an instance of BaseException.*"
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
raise IndexError from ConstructMortal
|
||||
|
||||
def test_instance_cause(self):
|
||||
cause = KeyError()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue