Skip to content

Annotation scopes containing nested scopes #109118

Closed
@15r10nk

Description

@15r10nk

Bug report

Bug description:

The following code causes a SystemError during compilation.

class name_2[*name_5, name_3: int]:
    (name_3 := name_4)

    class name_4[name_5: name_5]((name_4 for name_5 in name_0 if name_3), name_2 if name_3 else name_0):
        pass

output (Python 3.12.0rc2+):

SystemError: compiler_lookup_arg(name='name_3') with reftype=3 failed in <generic parameters of name_4>; freevars of code <genexpr>: ('name_3',)

removing the named-expression makes it worse and causes a crash

class name_2[*name_5, name_3: int]:

    class name_4[name_5: name_5]((name_4 for name_5 in name_0 if name_3), name_2 if name_3 else name_0):
        pass

output (Python 3.12.0rc2+):

Traceback (most recent call last):
  File "/home/frank/projects/pysource-codegen/bug2.py", line 2, in <module>
    class name_2[*name_5, name_3: int]:
  File "/home/frank/projects/pysource-codegen/bug2.py", line 2, in <generic parameters of name_2>
    class name_2[*name_5, name_3: int]:
  File "/home/frank/projects/pysource-codegen/bug2.py", line 4, in name_2
    class name_4[name_5: name_5]((name_4 for name_5 in name_0 if name_3), name_2 if name_3 else name_0):
  File "/home/frank/projects/pysource-codegen/bug2.py", line 4, in <generic parameters of name_4>
    class name_4[name_5: name_5]((name_4 for name_5 in name_0 if name_3), name_2 if name_3 else name_0):
                                                       ^^^^^^
NameError: name 'name_0' is not defined
Modules/gcmodule.c:113: gc_decref: Assertion "gc_get_refs(g) > 0" failed: refcount is too small
Enable tracemalloc to get the memory block allocation traceback

object address  : 0x7f4c77059a30
object refcount : 1
object type     : 0x560ea4b6cfe0
object type name: dict
object repr     : {'__module__': '__main__', '__qualname__': 'name_2', '__type_params__': (name_5, name_3)}

Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: finalizing (tstate=0x0000560ea4cc9ba0)

Current thread 0x00007f4c7756c280 (most recent call first):
  Garbage-collecting
  <no Python frame>

side note:
The reason for the strange looking language constructs and variable names is that I generated this code. I found it while working on my pysource-codegen library.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

Labels

3.13bugs and security fixestype-bugAn unexpected behavior, bug, or error

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions