Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
Tested with CPython 3.12.0rc3
importsymtabledeffoo[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 thesymtable 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 695https://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: TypeParamBlockhttps://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