GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Ambiguous symbol table names · Issue #121914 · python/cpython

Ambiguous symbol table names #121914

New issue
Copy link
New issue
Copy link
Closed
Closed
Ambiguous symbol table names#121914
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@serhiy-storchaka
serhiy-storchaka
opened on Jul 17, 2024
Issue body actions

Feature or enhancement

Every symbol table has type and name. The name of the symbol table that corresponds a class or a function is the same as the name of the corresponding class or function. But there are special symbol tables of type function for lambdas and generator expressions (there were also symbol tables for comprehensions, but they are no longer used). For lambdas. the name "lambda" does not conflict with other function names, because it is a reserved word. But for general expressions, the name "genexpr" can conflict with local function "genexpr" (see #119698). It is possible to distinguish the symbol table corresponding to a generator expression by looking in the list of its parameters, but this is not so convenient.

I propose to make the difference more clear:

  • Either use separate types for lambda and generator expression symbol tables.

  • Or use names which cannot be confused with any function name:

    • reserved word like lambda. But I do not know good variant for generator expression.
    • hyphenated word, like gen-expr.
    • angle brackets, like <genexpr> and <lambda>.
    • other special characters, e.g. .genexpr.

    Names of symbol tables of other types like top and __annotations__ can also be changed for uniformity and to avoid possible future conflicts.

The original issue #119698 was solved in other way, so there is no urge for such change. This is just a wild idea.

Linked PRs

  • gh-121914: Change the names of the symbol tables for lambda and genexpr #135288

Activity

  1. serhiy-storchaka
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Jul 17, 2024
  2. JelleZijlstra commented on Jul 17, 2024

    @JelleZijlstra
    JelleZijlstra
    on Jul 17, 2024
    Member
    More actions

    I think a leading dot is a good approach to get a name that doesn't conflict with user-defined names: it always works and it's already what we do in a few other places in the compiler pipeline (e.g., PEP 695 annotation scopes can have a compiler-created local variable called .type_params).

  3. picnixz commented on Jul 17, 2024

    @picnixz
    picnixz
    on Jul 17, 2024
    Member
    More actions

    was solved in other way

    Yes and I dislike that way although I couldn't come up with something else... It's a bit too fragile IMO =/

    I'm actually happy with both proposals:

    • different type: you can have checks of the form .type == TYPE_GENERATOR_EXPRESSION without exposing any name. The issue is that you introduce more types but I'm not sure whether something else needs to be changed in symtable.c.
    • special names: I like the dotted names and since they are already part of PEP 695, maybe it's fine to extend their usage. Having a reserved word is kind of introducing a new keyword and I'm pretty sure that you that you don't want genexpr to be a hard keyword (or any other kind of name, like maybe __Py_genexpr but I don't think we gain anything here...). For brackets, I think it's already the case for the repr() but not in the symbol table itself.
  4. serhiy-storchaka
    added a commit that references this issue on Jun 9, 2025

    pythongh-121914: Change the names of the symbol tables for lambda and…

    cce7fd9
  5. picnixz
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Jun 9, 2025
  6. serhiy-storchaka commented on Jun 9, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Jun 9, 2025
    MemberAuthor
    More actions

    New types for tables will require changing the compiler. Every time we check for FunctionBlock, we should add check for the new types. This can also affect third-party code. Special names would have less impact.

    <genexpr> and <lambda> have the following advantages over .genexpr and .lambda:

    • They match the name of the corresponding code object.
    • Since static string objects <genexpr> and <lambda> are already defined, this will allow to reduce the number of static string objects.
    • We can reuse <listcomp>, <setcomp> and <dictcomp> for temporary symbol tables for zero cost.
    • If we even display full qualified names for symbol tables, Class.meth.<genexpr> will look less ambiguous than Class.meth..genexpr.
  7. serhiy-storchaka commented on Jun 9, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Jun 9, 2025
    MemberAuthor
    More actions

    Since there may be several symbol tables with the same name, the name cannot be used to identify the symbol table. It is only used as a hint.

    I would also change the name of the top symbol table to <module>, but it is already documented as "top".

  8. serhiy-storchaka
    added a commit that references this issue on Jul 13, 2025

    gh-121914: Change the names of the symbol tables for lambda and genex…

    da699ed
  9. serhiy-storchaka
    closed this as completedon Jul 13, 2025
  10. taegyunkim
    added a commit that references this issue on Aug 4, 2025

    pythongh-121914: Change the names of the symbol tables for lambda and…

    81f2646
  11. Agent-Hellboy
    added a commit that references this issue on Aug 19, 2025

    pythongh-121914: Change the names of the symbol tables for lambda and…

    785ee66
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

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.