Description
Bug report
Bug description:
I tried searching for something related but I could not find exactly this case with super
. Maybe I missed… so posting it here.
Following code works fine:
class A:
def foo(self):
return 1
class B(A):
def foo(self):
return [super().foo() for _ in range(10)]
print(B().foo())
But if you modify it to be like this:
class A:
def foo(self):
return 1
class B(A):
def foo(self):
return list(super().foo() for _ in range(10))
print(B().foo())
you will get following error:
TypeError: super(type, obj): obj must be an instance or subtype of type
Before #101441 , [super().foo() for _ in range(10)]
would cause the same error but it was fixed implicitly by PEP709.
You can fix this yourself by specifying type and instance in super()
:
class A:
def foo(self):
return 1
class B(A):
def foo(self):
return list(super(B, self).foo() for _ in range(10))
print(B().foo())
If you decide that fixing this makes sense, can I work on fixing it? To me it makes sense (if you decide to leave it as it is) at least to give some kind of warning or error that in this case you should explicitly provide type and instance to super
, because it is quite confusing why user gets this error as semantically this is valid and should work
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux, macOS