mirror of https://github.com/python/cpython
bpo-46161: Fix bug in starunpack_helper in compile.c (GH-30235)
This commit is contained in:
parent
62a6594e66
commit
c118c2455c
|
@ -666,5 +666,23 @@ class ClassTests(unittest.TestCase):
|
|||
with self.assertRaisesRegex(TypeError, error_msg):
|
||||
object.__init__(E(), 42)
|
||||
|
||||
def testClassWithExtCall(self):
|
||||
class Meta(int):
|
||||
def __init__(*args, **kwargs):
|
||||
pass
|
||||
|
||||
def __new__(cls, name, bases, attrs, **kwargs):
|
||||
return bases, kwargs
|
||||
|
||||
d = {'metaclass': Meta}
|
||||
|
||||
class A(**d): pass
|
||||
self.assertEqual(A, ((), {}))
|
||||
class A(0, 1, 2, 3, 4, 5, 6, 7, **d): pass
|
||||
self.assertEqual(A, (tuple(range(8)), {}))
|
||||
class A(0, *range(1, 8), **d, foo='bar'): pass
|
||||
self.assertEqual(A, (tuple(range(8)), {'foo': 'bar'}))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix the class building error when the arguments are constants and CALL_FUNCTION_EX is used.
|
|
@ -4233,7 +4233,7 @@ starunpack_helper(struct compiler *c, asdl_expr_seq *elts, int pushed,
|
|||
Py_INCREF(val);
|
||||
PyTuple_SET_ITEM(folded, i, val);
|
||||
}
|
||||
if (tuple) {
|
||||
if (tuple && !pushed) {
|
||||
ADDOP_LOAD_CONST_NEW(c, folded);
|
||||
} else {
|
||||
if (add == SET_ADD) {
|
||||
|
@ -4245,6 +4245,9 @@ starunpack_helper(struct compiler *c, asdl_expr_seq *elts, int pushed,
|
|||
ADDOP_I(c, build, pushed);
|
||||
ADDOP_LOAD_CONST_NEW(c, folded);
|
||||
ADDOP_I(c, extend, 1);
|
||||
if (tuple) {
|
||||
ADDOP(c, LIST_TO_TUPLE);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue