The following code snippet gives error in python2 but no error with python3
class Steps(object):
def step(self, msg="Default"):
if not hasattr(self, "funky_attr"):
print('No attr')
print(self)
print(msg)
class FirstTest(Steps):
@classmethod
def test_setup(cls):
cls.step("This is the message")
if __name__ == '__main__':
C = FirstTest()
C.test_setup()
With python 2 it produces the error:
TypeError: unbound method step() must be called with CifsTest instance as first argument (got str instance instead)
While with python 3 it runs fine:
No attr
This is the message # Note here the 'self' is the str
Default
Is this the correct behavior ?
Python3 allows calling instance method from class methods ?