Why is it considered that bad practice rigidly sets the class name inside class methods?
This is not true. I donβt know why you think so.
There are many good reasons for hard coding a class name inside its methods. For example, using superin Python 2:
super(ClassName, self).whatever()
super(self.__class__, self).whatever(), , . , super, self.__class__, .
- . , , , , :
class Foo(object):
def big_complicated_calculation(self):
return
def slightly_different_calculation(self):
return self.big_complicated_calculation() + 2
, slightly_different_calculation big_complicated_calculation, Foo.big_complicated_calculation:
def slightly_different_calculation(self):
return Foo.big_complicated_calculation(self) + 2
, ClassName.whatever self.whatever self.__class__.whatever.