0

I'm getting this error:
unbound method hello() must be called with A instance as first argument(got nothing instead)

import B
class A():
   @staticmethod
   def newHello():
       A.oldHello() # Here the error
       print ' world'

   def inject(self):
       A.oldHello = B.hello
       B.hello = A.newHello


  A().inject()
  B.hello()

B.py contain only a function "hello" that print "hello"

def hello():
     print 'hello'

Thanks in advance

2
  • have you tried B with A instance as it suggests? What do you get? Commented Sep 26, 2014 at 16:05
  • do you mean call oldHello(A())? that the function hello got 1 argument,0 required Commented Sep 26, 2014 at 18:06

1 Answer 1

1

A.oldhello() is not static. So in B's hello function is referencing A's nonstatic oldhello statically. A does in fact need an instance. I'm not too good with the decorators and how they work but maybe try declaring oldhello in the class before the function and calling it @staticmethod. I don't know if the staticness carries over if you override the method.

Try this:

class B():
    def hello(self):
        print "hello"

class A():
   @staticmethod
   def newHello(self):
       A.oldHello(self) # Here the error
       print ' world'

   def inject(self):
       A.oldHello = B.hello
       B.hello = A.newHello

A().inject()
B().hello()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.