This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: `class A(1, 2, 3, **d): pass` gives bad bytecode
Type: crash Stage: resolved
Components: Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Dennis Sweeney, Mark.Shannon, zq1997
Priority: normal Keywords:

Created on 2021-12-23 07:03 by zq1997, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30235 merged zq1997, 2021-12-23 07:03
Messages (5)
msg409069 - (view) Author: Qiang Zhang (zq1997) * Date: 2021-12-23 07:03
Please refer to https://github.com/python/cpython/pull/30235
msg409073 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2021-12-23 08:53
Bisected to here:


13bc13960cc83dbd1cb5701d9a59ac9b9144b205 is the first bad commit
commit 13bc13960cc83dbd1cb5701d9a59ac9b9144b205
Author: Mark Shannon <mark@hotpy.org>
Date:   Thu Jan 23 09:25:17 2020 +0000

    bpo-39320: Handle unpacking of *values in compiler (GH-17984)

    * Add three new bytecodes: LIST_TO_TUPLE, LIST_EXTEND, SET_UPDATE. Use them to implement star unpacking expressions.

    * Remove four bytecodes BUILD_LIST_UNPACK, BUILD_TUPLE_UNPACK, BUILD_SET_UNPACK and  BUILD_TUPLE_UNPACK_WITH_CALL opcodes as they are now unused.

    * Update magic number and dis.rst for new bytecodes.



In debug mode, the following code gives fails a C-level assertion:

d = {'metaclass': type}
for _ in [1]:
    class A(1, 2, 3, **d):
        pass

Assertion failed: b->b_startdepth < 0 || b->b_startdepth == depth, file compile.c, line 6959
msg409079 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2021-12-23 09:37
I was trying to figure out how code like this could ever *not* raise an exception, and here is one case that runs to completion on 3.6--3.8, but it raises `TypeError: 'str' object is not callable` on 3.9--3.11.


class I(int):
    def __init__(*args, **kwargs): pass
    def __new__(*args, **kwargs): pass

d = {'metaclass': I}
class A(1, 2, 3, **d):
    pass
msg410813 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-01-17 17:45
New changeset c118c2455c95baea08045dc64963600b7a56b6fd by zq1997 in branch 'main':
bpo-46161: Fix bug in starunpack_helper in compile.c (GH-30235)
https://github.com/python/cpython/commit/c118c2455c95baea08045dc64963600b7a56b6fd
msg412734 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-02-07 11:34
Qiang Zhang, thanks for fixing this.
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90319
2022-02-07 11:34:54Mark.Shannonsetstatus: open -> closed
resolution: fixed
messages: + msg412734

stage: resolved
2022-01-17 17:45:58Mark.Shannonsetmessages: + msg410813
2021-12-23 09:37:03Dennis Sweeneysetmessages: + msg409079
2021-12-23 08:53:06Dennis Sweeneysetnosy: + Mark.Shannon, Dennis Sweeney
title: Incorrect bytecpde compilation for class -> `class A(1, 2, 3, **d): pass` gives bad bytecode
messages: + msg409073

versions: + Python 3.9, Python 3.10, Python 3.11
type: compile error -> crash
2021-12-23 07:03:06zq1997create