0

Imagine, there is a function like this

def bar(a: str, b: str):
    """
    Do somehting with a and b.
    """
    print(a, b)

Then there is a class, where i would like to adapt this function, but keep the docstring (and also the dynamic autocomplete and help) of the original function.

class Foo:
    def foo(self, **kwargs):
        bar(a=kwargs.get("a"), b=kwargs.get("b"))
        print("This was called fro the class method")

How do i dynamically link the original function to the class, including docstrings? And are kwargs the best way to pass the arguments, without repeating them in the definition of the class-method?

So when i type Foo.foo() in my IDE or jupyter notebook, i would like to see the docstring of foo().

F. Win
  • 390
  • 5
  • 17
  • Does this answer your question? [Inherit docstrings in Python class inheritance](https://stackoverflow.com/questions/2025562/inherit-docstrings-in-python-class-inheritance) – RvdK Dec 21 '22 at 07:55
  • @RvdK i found that already, but as i am not doing a class inheritance, i couldn't get it to work for my case – F. Win Dec 21 '22 at 08:18
  • See comment by https://stackoverflow.com/a/2025599/47351: have you tried: _ _ doc _ _ += bar.__doc__ – RvdK Dec 21 '22 at 10:11
  • Yes, i have tried, but it also does not work. Or i am putting it in wrong position. – F. Win Dec 21 '22 at 10:36

0 Answers0