Closed
Description
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
- gh-109118: Fix runtime crash when NameError happens in PEP 695 function #109123
- [3.12] gh-109118: Fix runtime crash when NameError happens in PEP 695 function (GH-109123) #109173
- gh-109118: Disallow nested scopes within PEP 695 scopes within classes #109196
- [3.12] gh-109118: Disallow nested scopes within PEP 695 scopes within classes (GH-109196) #109297
- gh-109118: Allow lambdas in annotation scopes in classes #118019
- gh-109118: Make comprehensions work within annotation scopes, but without inlining #118160
Metadata
Metadata
Assignees
Labels
bugs and security fixesbugs and security fixesAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
Done