Doesn't Python's Super() Built-in Violate Dry?
Solution 1:
On the one hand, DRY is more about large sections of code being duplicated; on the other hand, yes, the class name in super()
calls can become stale (it's happened to me).
In Python 3, super()
has been revamped to not require the class name, so long as the function is defined inside the class -- so not a problem unless you are monkey-patching.
Solution 2:
The same way self is called manually in python super is a simple function, I mean, python functions doesn't know the execution context. This behaviour is practical for monkey patching for example.
For example, I took your C class from pypi and you update it every month as it's a useful class. I want to modify it's method behaviour so it'll update the comportment of other of my requirements using your C class:
from utils import do_magic
from a import C
defmethod(self, arg):
super(C, self).method(arg)
do_magic(self)
C.method = method
Post a Comment for "Doesn't Python's Super() Built-in Violate Dry?"