Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitadb1bc4

Browse files
committed
fix a reference leak inraise E from T whenT is an exception
subtype for which `T.__new__` does not return an exception instance.
1 parentd12cbf2 commitadb1bc4

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

‎Lib/test/test_raise.py‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,14 @@ def test_class_cause(self):
186186
self.fail("No exception raised")
187187

188188
deftest_class_cause_nonexception_result(self):
189-
classConstructsNone(BaseException):
190-
@classmethod
189+
# See https://github.com/python/cpython/issues/140530.
190+
classConstructMortal(BaseException):
191191
def__new__(*args,**kwargs):
192-
returnNone
193-
try:
194-
raiseIndexErrorfromConstructsNone
195-
exceptTypeErrorase:
196-
self.assertIn("should have returned an instance of BaseException",str(e))
197-
exceptIndexError:
198-
self.fail("Wrong kind of exception raised")
199-
else:
200-
self.fail("No exception raised")
192+
return ["mortal value"]
193+
194+
msg=".*should have returned an instance of BaseException.*"
195+
withself.assertRaisesRegex(TypeError,msg):
196+
raiseIndexErrorfromConstructMortal
201197

202198
deftest_instance_cause(self):
203199
cause=KeyError()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a reference leak when ``raise exc from cause`` fails. Patch by Bénédikt
2+
Tran.

‎Python/ceval.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,6 +2148,7 @@ do_raise(PyThreadState *tstate, PyObject *exc, PyObject *cause)
21482148
"calling %R should have returned an instance of "
21492149
"BaseException, not %R",
21502150
cause,Py_TYPE(fixed_cause));
2151+
Py_DECREF(fixed_cause);
21512152
gotoraise_error;
21522153
}
21532154
Py_DECREF(cause);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp