Skip to content

Symbol table for type parameter (PEP 695) raises AssertionError on get_type() #110045

Closed

Description

@wookayin

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

Linked PRs

Activity

  1. AlexWaygood commented on Sep 28, 2023

    @AlexWaygood
    Member
  2. terryjreedy commented on Sep 29, 2023

    @terryjreedy
    Member

    Same error on Windows 10 and main.

  3. changed the title [-]Python 3.12: symbol table for type parameter (PEP 695) raises AssertionError on get_type()[/-] [+]Symbol table for type parameter (PEP 695) raises AssertionError on get_type()[/+] on Sep 29, 2023
  4. added 3 commits that reference this issue on Sep 29, 2023
  5. added a commit that references this issue on Sep 29, 2023
  6. added a commit that references this issue on Sep 29, 2023
  7. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.12only security fixes3.13only security fixestopic-typingtype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions