On Sun, 29 May 2022 at 08:26, Eryk Sun <eryk...@gmail.com> wrote: > > On 5/28/22, Chris Angelico <ros...@gmail.com> wrote: > > > > be extremely confusing; so to keep everything safe, the interpreter > > generates a name you couldn't possibly want - same as for the function > > itself, which is named "<listcomp>" or "<genexpr>", angle brackets > > included. > > To clarify, "<listcomp>" is the co_name and co_qualname value of the > code object, which was compiled for the list comprehension. These > names are also used as the __name__ and __qualname__ of the temporary > object that's created by MAKE_FUNCTION. They are not identifiers. The > code object is a constant, which is referenced solely by its index in > the co_consts tuple. The temporary function is referenced on the > stack.
Correct. Every function has a name, important for tracebacks and such, but with lambda functions, the internal functions of comprehensions, and so on, there's no actual name binding for it. So the interpreter generates a name that won't collide with any actual name that you'd have assigned anything to. ChrisA -- https://mail.python.org/mailman/listinfo/python-list