0

Let's say I have the following function:

def person(*args, **kwargs):
    '''
       person(name, age, parents=2)
       this is a docstring.
    '''

If I execute help(person) I would get

person(*args, **kwargs)
    person(name, age, children=5)
    this is a docstring.

But instead, I want to see:

person(name, age, children=5)
    this is a docstring.
Tomergt45
  • 579
  • 1
  • 7
  • 19

2 Answers2

1

You can simply overwrite .__doc__ attribute:

def a():
    """orig docstring"""
    pass
help(a)
a.__doc__ = """modified docstring"""
help(a)
Jan Stránský
  • 1,671
  • 1
  • 11
  • 15
  • I tried to edit my question to make it a bit more clear. My question is not how to set the docstring of the function but rather changing the signature (i.e. when calling `help(person)` I don't want to see `person(*args, **kwargs)` but rather `person(name, age, parents=2)` ONLY. – Tomergt45 Aug 19 '20 at 14:21
0

You could always use docstrings, like this:

def function(...):
    """
    This function does this and that. The parameters are the following:
    param1 = ...
    param2 = ...
    ...
    """
    # code

Then you can simply call the .doc method and it prints out the docstring. It works like this:

    print.__doc__

Or for better readability:

    import pprint
    pprint.pprint(pprint.__doc__, indent=4)

Pprint is pretty print.

Jan Stránský
  • 1,671
  • 1
  • 11
  • 15
Yeji Ha
  • 86
  • 6
  • This is not what I asked. I asked how you can override the original signature of a function, for example, if you press `shift+tab` to see the doc of a function in jupyter notebook you will be presented with the function signature and doc string, what I want is to either override the function signature or hide it. – Tomergt45 Aug 19 '20 at 14:12
  • 1
    "This is not what I asked" - as you see from this answer and also the discussion below OP, it is not really clear what you have asked.. – Jan Stránský Aug 19 '20 at 14:13
  • To be honest, your question was rather vague. To my knowledge, overriding (as in C++) is not possible in Python. – Yeji Ha Aug 19 '20 at 14:13
  • Excuse me if wasn't clear enough, I am trying to achieve something like in [this](https://stackoverflow.com/questions/12082570/override-function-declaration-in-autodoc-for-sphinx/12087750#12087750) answer but it doesn't seem to work for me, hence my question. – Tomergt45 Aug 19 '20 at 14:14