diff options
| author | 2021-07-23 12:14:28 +0100 | |
|---|---|---|
| committer | 2021-07-23 12:14:28 +0100 | |
| commit | 39500b40ac2892cb469366103022bd854f7734b2 (patch) | |
| tree | 3e8baffc9b7f0fc621b253de5a309334724f131f | |
| parent | Update grammer in docstring tag (diff) | |
Suggest inspect.getdoc in docstring tag
Co-authored-by: Numerlor <[email protected]>
| -rw-r--r-- | bot/resources/tags/docstring.md | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/bot/resources/tags/docstring.md b/bot/resources/tags/docstring.md index 0160d5ff3..20043131e 100644 --- a/bot/resources/tags/docstring.md +++ b/bot/resources/tags/docstring.md @@ -11,6 +11,8 @@ def greet(name: str, age: int) -> str: """ return f"Hello {name}, you are {age} years old!" ``` -You can get the docstring by using the `.__doc__` attribute. For the last example, you can print it by doing this: `print(greet.__doc__)`. +You can get the docstring by using the [`inspect.getdoc`](https://docs.python.org/3/library/inspect.html#inspect.getdoc) function, from the built-in [`inspect`](https://docs.python.org/3/library/inspect.html) module, or by accessing the `.__doc__` attribute. `inspect.getdoc` is often preferred, as it clears indents from the docstring. + +For the last example, you can print it by doing this: `print(inspect.getdoc(greet))`. For more details about what a docstring is and its usage, check out this guide by [Real Python](https://realpython.com/documenting-python-code/#docstrings-background), or the [official docstring specification](https://www.python.org/dev/peps/pep-0257/#what-is-a-docstring). |