It is not possible to rewrite the code in this way. The closest you can do is something like:
class MyClass:
pass
def test(x, y, z=external_function(MyClass):
pass
MyClass.test = staticmethod(test)
del test
Note that this assumes Python 3; in Python 2, you may need to work with a module new. But, although it is possible, the intent of the code is very unobvious. It’s best to stick with if z is Noneor reorganize your code so that it does not need it.
source
share