Josh Rosenberg <shadowranger+pyt...@gmail.com> added the comment:

Carlos: This has nothing to do with reloading (as Alex's repro shows, no reload 
calls are made).

super() *should* behave the same as super(CLASS_DEFINED_IN, self), and it looks 
like the outer function is doing half of what it must do to make no-arg super() 
work in the genexpr (dis.dis reports that __class__ is being loaded, and a 
closure constructed from the genexpr that includes it, so __class__, which 
no-arg super pulls from closure scope to get its first argument, is there).

The problem is that super() *also* assumes the first argument to the function 
is self, and a genexpr definitionally receives just one argument, the iterator 
(the outermost one for genexprs with nested loops). So no-arg super is doing 
the equivalent of:

super(__class__, iter(vars))

when it should be doing:

super(__class__, self)

Only way to fix it I can think of would be one of:

1. Allow a genexpr to receive multiple arguments to support this use case 
(ugly, requires significant changes to current design of genexprs and probably 
super() too)
2. Somehow teach super() to pull self (positional argument #1 really; super() 
doesn't care about names) from closure scope (and make the compiler put self in 
the closure scope when it builds the closure) when run in a genexpr.

Both options seem... sub-optimal. Better suggestions welcome. Note that the 
same problem affects the various forms of comprehension as well (this isn't 
specific to the lazy design of genexprs; listcomps have the same problem).

----------
nosy: +josh.r

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46175>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to