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.

classification
Title: super() does not work in nested functions, genexps, listcomps, and gives misleading exceptions
Type: Stage:
Components: Interpreter Core Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, jleedev, rhettinger, xtreak, ztane
Priority: normal Keywords:

Created on 2016-03-06 18:47 by ztane, last changed 2022-04-11 14:58 by admin.

Messages (1)
msg261266 - (view) Author: Antti Haapala (ztane) * Date: 2016-03-06 18:57
super() without arguments gives proper "super() without arguments" in functions, generator functions nested in methods, if *those* do not have arguments. But if you use super() in a nested function that takes an argument, or in a generator expression or a comprehension, you'd get 

    Got exception: TypeError super(type, obj): obj must be an instance or subtype of type

which is really annoying. Furthermore, if a nested function took another instance of type(self) as the first argument, then super() could refer unexpectedly to wrong instance:

    class Bar(Foo):
        def calculate(self, other_foos):
            def complicated_calculation(other):
                super().some_method(other)

            for item in other_foos:
                complicated_calculation(item)

now the `super()` call would not have implied `self` of `calculate` as the first argument, but the `other` argument of the nested function, all without warnings.

I believe it is a mistake that these nested functions can see `__class__` at all, since it would just mostly lead them misbehaving unexpectedly.
History
Date User Action Args
2022-04-11 14:58:28adminsetgithub: 70682
2020-01-09 18:40:36jleedevsetnosy: + jleedev
2018-09-21 12:19:17xtreaksetnosy: + xtreak
2016-03-13 07:27:36rhettingersetmessages: - msg261264
2016-03-10 22:13:04eric.snowsetnosy: + rhettinger, benjamin.peterson
2016-03-06 18:57:29ztanesetmessages: + msg261266
components: + Interpreter Core
title: super() does not work nested -> super() does not work in nested functions, genexps, listcomps, and gives misleading exceptions
2016-03-06 18:47:20ztanecreate