Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wookayin opened this issue Sep 28, 2023 · 2 comments
Closed
Assignees
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes topic-typing type-bug An unexpected behavior, bug, or error

Comments

@wookayin
Copy link

wookayin commented Sep 28, 2023

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

@wookayin wookayin added the type-bug An unexpected behavior, bug, or error label Sep 28, 2023
@AlexWaygood
Copy link
Member

Cc. @JelleZijlstra @carljm

@AlexWaygood AlexWaygood added topic-typing 3.12 bugs and security fixes 3.13 bugs and security fixes labels Sep 28, 2023
@JelleZijlstra JelleZijlstra self-assigned this Sep 28, 2023
@terryjreedy
Copy link
Member

Same error on Windows 10 and main.

@terryjreedy terryjreedy 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() Sep 29, 2023
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue Sep 29, 2023
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue Sep 29, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 29, 2023
(cherry picked from commit 7dc2c50)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Yhg1s pushed a commit that referenced this issue Sep 29, 2023
…0070)

gh-110045: Update symtable module for PEP 695 (GH-110066)
(cherry picked from commit 7dc2c50)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants