My question is about two answers to another question: http://stackoverflow.com/questions/3083692/using-class-static-methods-as-default-parameter-values-within-methods-of-the-same.
I am trying to understand if there's really a difference between what the two answers do, and if so, what's the pros and cons of each.
Question: how to use a class method as a default parameter to a method in the same class.
Answer 1: use a function instead of a class method
class X:
def default_func(x):
return True
def test(self, func = default_func):
return func(self)
Answer 2: use a class method, but convert it to a function
def unstaticmethod(static):
return static.__get__(None, object)
class X:
@staticmethod
def default_func(x):
return True
def test(self, func = unstaticmethod(default_func)):
return func(self)
This was originally written in Python 2, but my summary is (hopefully) Python 3.