Closed
Description
Bug report
Bug description:
Tested with CPython 3.12.0rc3
import symtable def foo[T](): return "bar" t_mod = symtable.symtable("""\ def foo[T](): return "bar" """, '?', 'exec') t_T = t_mod.get_children()[0] print(t_T.get_type())
Traceback (most recent call last): File ".../bug_symtable.py", line 12, in <module> print(t_T.get_type()) ^^^^^^^^^^^^^^ File ".../3.12.0rc3/lib/python3.12/symtable.py", line 74, in get_type assert self._table.type in (1, 2, 3), \ AssertionError: unexpected type: 6 [Finished in 1 seconds with code 1]
The symbol table for type parameters (generic) seem to have a new type, but it appears that the symtable
implementation was not updated accordingly. Also there is no _symtable.TYPE_*
constant for type code 6 (see _symtable).
https://github.com/python/cpython/blob/3.12/Lib/symtable.py#L62-L75
https://github.com/python/cpython/blob/main/Lib/symtable.py#L62-L75
There are new block types introduced by PEP 695 https://github.com/python/cpython/blob/3.12/Include/internal/pycore_symtable.h#L13-L23
- 0: FunctionBlock - 1: ClassBlock - 2: ModuleBlock // Used for annotations 'from __future__ import annotations' - 3: AnnotationBlock // Used for generics and type aliases. These work mostly like functions // (see PEP 695 for details). The three different blocks function identically; // they are different enum entries only so that error messages can be more // precise. - 4: TypeVarBoundBlock - 5: TypeAliasBlock - 6: TypeParamBlock
https://github.com/python/cpython/blob/3.12/Include/internal/pycore_symtable.h#L13-L23
Hope this can be fixed by the 3.12 GA release.
CPython versions tested on:
3.12.0rc3
Operating systems tested on:
macOS