Skip to content

SystemError: no locals found when a type parameter bound names a later private type parameter of a class #162597

Backlog

Description

@Robertboy18

Bug report

Bug description:

In class C[T: __U, __U] the bound of T names the type parameter __U that comes after it. Evaluating the bound raises SystemError, while with the order reversed it gives the type parameter:

class C[T: __U, __U]:
    pass
class D[__U, T: __U]:
    pass
print(D.__type_params__[1].__bound__)
try:
    print(C.__type_params__[0].__bound__)
except SystemError as e:
    print("SystemError:", e)

CPython 3.15.2 and main (639c34b):

__U
SystemError: no locals found

SystemError is for internal errors (SystemError). The symbol table adds a private type parameter to ste_mangled_names only when it reaches it, so the earlier bound records __U unmangled; the compiler then mangles it with the complete set (_Py_MaybeMangle), finds no symbol for _C__U and emits LOAD_NAME in the bound's function scope, which has no locals. Here the name belongs to a later type parameter; gh-162574 concerns a private name from an enclosing class. I found it while writing a Lean spec of Python.

CPython versions tested on:

3.15, CPython main branch

Operating systems tested on:

Linux

Activity

  1. added
    AI-needs-explanation
    on Nov 25, 2026
  2. bedevere-app commented on Nov 25, 2026

    @bedevere-app
  3. added
    type-bug
    interpreter-core
    and removed
    AI-needs-explanation
    on Nov 25, 2026
  4. picnixz commented on Nov 25, 2026

    @picnixz
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-coretopic-parsertopic-typingtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions