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-128049: Fix type confusion bug with the return value of a custom ExceptionGroup split function#128079

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
iritkatriel merged 7 commits intopython:mainfromNico-Posada:fix-issue-128049
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
NextNext commit
code review changes
  • Loading branch information
@Nico-Posada
Nico-Posada committedDec 20, 2024
commit05d809b2aa294c690e3cef5494aeb8c7f08ee6ec
18 changes: 7 additions & 11 deletionsLib/test/test_except_star.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -952,10 +952,8 @@ def derive(self, excs):
self.assertExceptionIsLike(tes, FalsyEG("eg", [TypeError(1)]))
self.assertExceptionIsLike(ves, FalsyEG("eg", [ValueError(2)]))

def test_bad_exception_group_subclass_split_func(self):
# See https://github.com/python/cpython/issues/128049
# tuples that return less than 2 values should
# result in a type error with the original eg chained to it
def test_exception_group_subclass_with_bad_split_func(self):
# see gh-128049.
class BadEG1(ExceptionGroup):
def split(self, *args):
return "NOT A 2-TUPLE!"
Expand All@@ -971,20 +969,18 @@ def split(self, *args):
r"split must return a 2-tuple, got tuple of size 1")
]

forEG, MSG in eg_list:
with self.assertRaisesRegex(TypeError,MSG) as m:
foreg_class, msg in eg_list:
with self.assertRaisesRegex(TypeError,msg) as m:
try:
raiseEG
raiseeg_class
except* ValueError:
pass
except* OSError:
pass

self.assertExceptionIsLike(m.exception.__context__,EG)
self.assertExceptionIsLike(m.exception.__context__,eg_class)

# although it isn't expected, still allow tuples of length > 2
# all tuple items past the second one will be ignored
# this quirk may be deprecated in the future
# we allow tuples of length > 2 for backwards compatibility
class WeirdEG(ExceptionGroup):
def split(self, *args):
return super().split(*args) + ("anything", 123456, None)
Expand Down
17 changes: 7 additions & 10 deletionsPython/ceval.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2096,23 +2096,20 @@ _PyEval_ExceptionGroupMatch(PyObject* exc_value, PyObject *match_type,
return -1;
}

if (!PyTuple_CheckExact(pair))
{
if (!PyTuple_CheckExact(pair)) {
PyErr_Format(PyExc_TypeError,
"%.200s.split must return a tuple, not %.200s",
Py_TYPE(exc_value)->tp_name, Py_TYPE(pair)->tp_name);
"%.200s.split must return a tuple, not %.200s",
Py_TYPE(exc_value)->tp_name, Py_TYPE(pair)->tp_name);
Py_DECREF(pair);
return -1;
}

// NOTE due to a previous bug which allowed tuples of length > 2 to
// work without problem, we are still allowing them to work even
// though the error says otherwise
// allow tuples of length > 2 for backwards compatibility
if (PyTuple_GET_SIZE(pair) < 2) {
PyErr_Format(PyExc_TypeError,
"%.200s.split must return a 2-tuple, "
"got tuple of size %zd",
Py_TYPE(exc_value)->tp_name, PyTuple_GET_SIZE(pair));
"%.200s.split must return a 2-tuple, "
"got tuple of size %zd",
Py_TYPE(exc_value)->tp_name, PyTuple_GET_SIZE(pair));
Py_DECREF(pair);
return -1;
}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp