python / cpython

The Python programming language
https://www.python.org
Other
61.99k stars 29.8k forks source link

Ambiguous symbol table names #121914

Open serhiy-storchaka opened 1 month ago

serhiy-storchaka commented 1 month ago

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:

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

JelleZijlstra commented 1 month ago

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).

picnixz commented 1 month ago

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: