Calling Python static methods using the class name is more common, but can be a real eye sore for long class names. Sometimes I use self within the same class to call the static methods, because I find it looks cleaner.
class ASomewhatLongButDescriptiveClassName:
def __init__(self):
# This works, but it's an eyesore
ASomewhatLongButDescriptiveClassName.do_something_static()
# This works too and looks cleaner.
self.do_something_static()
@staticmethod
def do_something_static():
print('Static method called.')
My understanding is that calling a static method with self gets interpreted as ClassName.static_method(self), where self would be ignored by the static method.
(EDIT: The above statement is only true for instance methods, not static methods)
Are there any concrete reasons why I should not use self to call static methods within the same class?
FWIW This is a sister question to Difference between calling method with self and with class name?, which deals with non-static methods.
"I understand that calling a static method with self is the same as ClassName.static_method(self) [...]"no it's not the same. That's only true for instance methods. Though you are using it correctly in your example, so I guess you are just misquoting a comment from the other linked SO question.__init__in your example, then by all means useself. Of course, if you want to access the method from outside an instance,selfwill have no meaning, so you'll have to use the full class name.foo = ASomewhatLongButDescriptiveClassName(), you should access the static method viafoo.do_something_static().staticmethodand just use a regular, module-level function.