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

gh-146199: Fix error handling incode_richcompare whenPyObject_RichCompareBool fails#146200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 5 commits intopython:mainfrombkap123:codeobject-richcomp
Mar 23, 2026
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletionsLib/test/test_code.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1164,6 +1164,18 @@ def test_stateless(self):
with self.assertRaises(Exception):
_testinternalcapi.verify_stateless_code(func)

def test_code_richcompare_raise_exception(self):
class BadStr(str):
def __eq__(self, _):
raise RuntimeError("Poison!")

__hash__ = str.__hash__

c1 = compile("pass", "test", "exec")
c2 = c1.replace(co_name=BadStr("poison"))
c3 = compile("pass", "poison", "exec")
with self.assertRaises(RuntimeError):
c2 == c3

def isinterned(s):
return s is sys.intern(('_' + s + '_')[1:-1])
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
Comparison of code objects now handles errors correctly.
2 changes: 1 addition & 1 deletionObjects/codeobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2606,7 +2606,7 @@ code_richcompare(PyObject *self, PyObject *other, int op)
cp = (PyCodeObject *)other;

eq = PyObject_RichCompareBool(co->co_name, cp->co_name, Py_EQ);
if (!eq) goto unequal;
if (eq <= 0) goto unequal;
eq = co->co_argcount == cp->co_argcount;
if (!eq) goto unequal;
eq = co->co_posonlyargcount == cp->co_posonlyargcount;
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp