diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-05-26 09:30:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-26 09:30:55 (GMT) |
commit | 7b3b6982a5683f5146ede58a448d3edb777e501b (patch) | |
tree | cdeb80f99a6008afb4a6610e4276d17b108055cf /Objects | |
parent | 2442b342bcbaf24334be7f70fb695d277c7a9a13 (diff) | |
download | cpython-7b3b6982a5683f5146ede58a448d3edb777e501b.zip cpython-7b3b6982a5683f5146ede58a448d3edb777e501b.tar.gz cpython-7b3b6982a5683f5146ede58a448d3edb777e501b.tar.bz2 |
bpo-44232: Fix type_new() error reporting (GH-26359) (GH-26365)
Fix a regression in type() when a metaclass raises an exception. The
C function type_new() must properly report the exception when a
metaclass constructor raises an exception and the winner class is not
the metaclass.
(cherry picked from commit bd199e72fb60a8ff001a023f23925092a290be91)
Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 8f67648..a551402 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3256,6 +3256,9 @@ type_new_get_bases(type_new_ctx *ctx, PyObject **type) if (winner->tp_new != type_new) { /* Pass it to the winner */ *type = winner->tp_new(winner, ctx->args, ctx->kwds); + if (*type == NULL) { + return -1; + } return 1; } @@ -3307,6 +3310,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) PyObject *type = NULL; int res = type_new_get_bases(&ctx, &type); if (res < 0) { + assert(PyErr_Occurred()); return NULL; } if (res == 1) { |