This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author josh.r
Recipients TobiasHT, carlosdamazio, josh.r, serhiy.storchaka, tritium
Date 2021-12-28.05:11:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1640668309.5.0.117739705621.issue46175@roundup.psfhosted.org>
In-reply-to
Content
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).
History
Date User Action Args
2021-12-28 05:11:50josh.rsetrecipients: + josh.r, serhiy.storchaka, tritium, carlosdamazio, TobiasHT
2021-12-28 05:11:49josh.rsetmessageid: <1640668309.5.0.117739705621.issue46175@roundup.psfhosted.org>
2021-12-28 05:11:49josh.rlinkissue46175 messages
2021-12-28 05:11:48josh.rcreate