title: How to get wrapped func.__code__.co_filename with decorator?
body: <p>A simple folder structure shown below, and all the functions in test.py have keyword decorator on it.</p>
  <pre><code> lib
    |--- keyword.py
   main
    |--- test.py
  </code></pre>
  <p>Keyword.py</p>
  <pre><code>from functools import wraps
  def keyword(name=None, tags=(), types=()):
  
      def _method_wrapper(func):
  
          @wraps(func)
          def _passargs(self, *args, **kwargs):  
              print(func.__code__.co_filename)  # --&gt; '..\main\test.py'
              return func(self, *args, **kwargs)
  
          print(_passargs.__code__.co_filename)  # --&gt; '..\lib\keyword.py'
                  
          return _passargs
  
      return _method_wrapper 
  </code></pre>
  <p><em>notes: <code>print(..)</code> is just an example, I need both <code>_passargs</code> &amp; <code>func</code> to have the same code object, instead of printing another variable :)</em></p>
  <p>As you can see, the <code>_passargs</code> got the wrong <code>co_filename</code>.</p>
  <p>This is from <code>robotframework</code> keyword.py, and I modified it for my own purpose. However I failed to figure out how to make both <code>_passargs</code> &amp; <code>func</code> have the correct source file location so the <code>robot.libdoc</code> can generate doc.libspec correctly.</p>
  <p>Can anyone help?</p>
  <p><strong>The expectation</strong></p>
  <pre><code>func.__code__.co_filename = '..\main\test.py'
  _passargs.__code__.co_filename = '..\main\test.py'
  </code></pre>
  <p>Python version = 3.8.10</p>