title: Dynamically add function to class through decorator
body: <p>I'm trying to find a way to dynamically add methods to a class through decorator.
  The decorator i have look like:</p>
  <pre><code>def deco(target):
  
      def decorator(function):
          @wraps(function)
          def wrapper(self, *args, **kwargs):
              return function(*args, id=self.id, **kwargs)
  
          setattr(target, function.__name__, wrapper)
          return function
  
      return decorator
  
  class A:
      pass
  
  # in another module
  @deco(A)
  def compute(id: str):
      return do_compute(id)
  
  # in another module
  @deco(A)
  def compute2(id: str):
      return do_compute2(id)
  
  # **in another module**
  a = A()
  a.compute() # this should work
  a.compute2() # this should work
  </code></pre>
  <p>My hope is the decorator should add the <code>compute()</code> function to class A, any object of A should have the compute() method.
  However, in my test, this only works if i explicitly import compute into where an object of A is created. I think i'm missing something obvious, but don't know how to fix it. appreciate any help!</p>