Python "private" classmethod and DRY
Sometimes a class will have "private" @classmethod
which calls other methods:
class FooClassThisSometimesHasALongNameEspIfAUnittestSubclasss(...):
@classmethod
def foo():
...
def bar(self):
...
FooClassThisSometimesHasALongNameEspIfAUnittestSubclasss.foo()
...
As you can see, the class name is repeated; it's admittedly probably not serious enough to cause a tech crash followed by a zombie apocalypse, but it's still a DRY violation and somewhat annoying.
The answer to a similar question aboutsuper
stated that this is one of the reasons for Py3 newsuper
.
In the absence of any magic function normal()
(which, unlike super()
, returns the current class), is there a way to avoid repetition?
+3
source to share