Message416773
> Anthony Sottile provided this search to showing that at least a few popular projects are using the one argument form of super():
Thanks for the link. But it gives lots of false positives. Only two popular projects (> 1k stars) use autosuper (urwid and evennia):
https://sourcegraph.com/search?q=context:global+setattr%5C%28.*super%5C%28.*%5C%29%5C%29+file:%5C.py%24+-file:test.*%5C.py%24&patternType=regexp&case=yes
The remaining projects use one-argument super incorrectly, as `super(cls).method()`, which looks up the method directly on class `super`:
https://sourcegraph.com/search?q=context:global+content:%5B%5E_%5Dsuper%5C%28%5Cw%2B%5C%29%5B%5E:%5D+file:%5C.py%24+-file:test.*%5C.py%24&patternType=regexp&case=yes
It is either a loud bug, which raises an `AttributeError`:
```
>>> class A:
... def f(self): pass
...
>>> class B(A):
... def f(self): super(B).f()
...
>>> B().f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in f
AttributeError: 'super' object has no attribute 'f'
```
Or worse with `super(cls).__init__()` (99% of the cases), it is a SILENT bug, which call the constructor of class `super` instead of the parent constructor, leaving the object in an incompletely initialized state:
```
>>> class A:
... def __init__(self): print('hello')
...
>>> class B(A):
... def __init__(self): super(B).__init__()
...
>>> A()
hello
<__main__.A object at 0x10926e460>
>>> B()
<__main__.B object at 0x10926e520>
``` |
|
Date |
User |
Action |
Args |
2022-04-05 11:59:10 | maggyero | set | recipients:
+ maggyero, gvanrossum, rhettinger |
2022-04-05 11:59:10 | maggyero | set | messageid: <1649159950.06.0.258022954086.issue44090@roundup.psfhosted.org> |
2022-04-05 11:59:10 | maggyero | link | issue44090 messages |
2022-04-05 11:59:09 | maggyero | create | |
|