docstring

Referencing parameters in a Python docstring

南楼画角 提交于 2019-12-04 02:02:28
I use Sphinx and the autodocs feature to ensure we have good docs in our project. So I'm familiar with info field lists and I'm familiar with using cross-referencing in our docs. However, when writing docstring for a method or function I find it useful to refer to their parameters in the text. But there doesn't seem to be a structured way to do this. We could say e.g. Use ``name`` to set the username but that has no structure, requires you to remember what style you used for that and if you change style you have to hunt down and kill all the incorrect styles. :param: doesn't work outside of a

Replacing python docstrings [closed]

感情迁移 提交于 2019-12-03 14:37:26
I have written a epytext to reST markup converter, and now I want to convert all the docstrings in my entire library from epytext to reST format. Is there a smart way to read the all the docstrings in a module and write back the replacements? ps: ast module perhaps? Pyment is a tool that can convert Python docstrings and create missing ones skeletons. It can manage Google , Epydoc (javadoc style), Numpydoc , reStructuredText (reST, Sphinx default) docstring formats. It accepts a single file or a folder (exploring also sub-folders). For each file, it will recognize each docstring format and

How to stop PyCharm from populating docstrings?

二次信任 提交于 2019-12-03 12:01:41
If I add a docstring to a method using the triple-quote, as soon as I type a space after the triple-quote, PyCharm will populate the docstring with the parameters the method takes, and a return value, like so: def fill_blank(self, direction): """ :param direction: :return: """ I've searched the PyCharm preferences for "docstring" and "stub" and turned off everything that shows up, even if it doesn't seem to pertain to this particular behavior; and I've googled high and low, but can't figure out how make it stop. Does anyone know how? (This is in PyCharm CE 3.4) You need to set the docstrings

In Django RestFramework, how to change the Api Root documentation?

三世轮回 提交于 2019-12-03 08:48:19
问题 In django RestFramework, is there any "official" way to generate the documentation for the "Api Root" ? After looking at the RestFramework's source code, I've found a work around by subclassing the DefaultRouter: from rest_framework import routers class MyRouter(routers.DefaultRouter): def get_api_root_view(self): api_root_view = super(MyRouter, self).get_api_root_view() ApiRootClass = api_root_view.cls class MyAPIRoot(ApiRootClass): """My API Root documentation""" pass return MyAPIRoot.as

function name + tab does not return docstring in IPython

穿精又带淫゛_ 提交于 2019-12-03 06:44:25
问题 In IPython, I am used to write function( and then strike a tab, and get the contents of the docstring and a list of the named arguments. However, this stopped working since I installed IPython 2.0. Is there an explanation or a know fix? 回答1: Oh, the shortcut is now shift+tab . 回答2: Shift-tab only works when you place the edit cursor inside or after the object. Not when it's at the start of the object. This gotcha is not documented anywhere...! I filed jupyter issue Shift-Tab completion doesn

How do I document :rtype: for a function that returns multiple possible data types? [duplicate]

空扰寡人 提交于 2019-12-03 06:26:08
This question already has answers here : How to specify multiple return types using type-hints (2 answers) In a Python docstring how should one document the :rtype: for a function that can return multiple possible data types? For example, if a function can return defaultdict OR dict OR list , based on the functions parameters, how do you document this? Code example: from collections import defaultdict def read_state(state_file, state_file_type='defaultdict'): """Deserialize state file or create empty state and return it. :param state_file: The path and file name of state file to read. :type

Are there any real alternatives to reStructuredText for Python documentation? [closed]

空扰寡人 提交于 2019-12-03 00:53:13
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I'm starting an open source Python project shortly and I'm trying to decide in advance how to write my docstrings. The obvious answer would be using reStructuredText and Sphinx with autodoc, because I really like the idea of simply properly documenting my code in my docstrings then have Sphinx automatically

In Django RestFramework, how to change the Api Root documentation?

孤街浪徒 提交于 2019-12-02 22:41:50
In django RestFramework, is there any "official" way to generate the documentation for the "Api Root" ? After looking at the RestFramework's source code, I've found a work around by subclassing the DefaultRouter: from rest_framework import routers class MyRouter(routers.DefaultRouter): def get_api_root_view(self): api_root_view = super(MyRouter, self).get_api_root_view() ApiRootClass = api_root_view.cls class MyAPIRoot(ApiRootClass): """My API Root documentation""" pass return MyAPIRoot.as_view() router = MyRouter() Is there a cleaner or better way ? Shih-Wen Su I'm new to this but I found you

function name + tab does not return docstring in IPython

跟風遠走 提交于 2019-12-02 20:24:16
In IPython, I am used to write function( and then strike a tab, and get the contents of the docstring and a list of the named arguments. However, this stopped working since I installed IPython 2.0. Is there an explanation or a know fix? Oh, the shortcut is now shift+tab . Shift-tab only works when you place the edit cursor inside or after the object. Not when it's at the start of the object. This gotcha is not documented anywhere...! I filed jupyter issue Shift-Tab completion doesn't work when edit cursor is at the start of the object #1902 来源: https://stackoverflow.com/questions/22850566

Are there any real alternatives to reStructuredText for Python documentation? [closed]

好久不见. 提交于 2019-12-02 14:16:56
I'm starting an open source Python project shortly and I'm trying to decide in advance how to write my docstrings. The obvious answer would be using reStructuredText and Sphinx with autodoc, because I really like the idea of simply properly documenting my code in my docstrings then have Sphinx automatically construct an API doc for me. The problem is the reStructuredText syntax it uses - I think it's completely unreadable before it's rendered. For instance: :param path: The path of the file to wrap :type path: str :param field_storage: The :class:`FileStorage` instance to wrap :type field