Skip to content

Commit 429ed98

Browse files
miss-islingtonjelle-openaiJelleZijlstra
authored
[3.15] gh-159739: [typing] Handle generic alias construction errors (GH-159772) (#159909)
(cherry picked from commit 07df106) Co-authored-by: Jelle Zijlstra <jelle@openai.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent c75c72b commit 429ed98

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Propagate errors during generic class construction and avoid a crash after
2+
failed generic alias substitution.

‎Objects/genericaliasobject.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ subs_tvars(PyObject *obj, PyObject *params,
303303
PyTuple_GET_SIZE(arg));
304304
if (j < 0) {
305305
Py_DECREF(subparams);
306-
Py_DECREF(subargs);
306+
assert(subargs == NULL);
307307
return NULL;
308308
}
309309
continue;

‎Objects/typevarobject.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,6 +2359,9 @@ _Py_subscript_generic(PyThreadState* unused, PyObject *params)
23592359
return NULL;
23602360
}
23612361
params = unpack_typevartuples(params);
2362+
if (params == NULL) {
2363+
return NULL;
2364+
}
23622365
PyObject *args[2] = {(PyObject *)interp->cached_objects.generic_type, params};
23632366
PyObject *result = call_typing_func_object("_GenericAlias", args, 2);
23642367
Py_DECREF(params);

0 commit comments

Comments
 (0)