docstring

Docstring tag for 'yield' keyword

不问归期 提交于 2019-12-06 18:18:21
问题 There are some tags for docstrings in python, like @param and @return , for example: def my_method(a_param): ''' @param a_param: Description of this param @return: The return value of the method ''' return int(a_param) * (other or 1) What can I use for documenting generators? specially the yield keyword, like: def my_generator(from=0): ''' @param from: The initial value @yield: A lot of values ''' yield a_value I understand that @return an iterator can be used here, but I don't know if it's

More than 1 docstrings for a single module/function etc.?

老子叫甜甜 提交于 2019-12-06 04:44:34
问题 I'm using python 3.1. Is it possible to create more than 1 docstring for a single module or function? I'm creating a program, and I'm intending to have multiple docstrings with a category for each. I intend to give other people the program so they can use it, and to make things easy for programmers and non-programmers alike, I'm putting a reference to the docstring for documentation within the program itself. To be more specific, I have a menu in the program/module as an interface, and one of

Automatically Generate GitHub Wiki Documentation from Python Docstrings

耗尽温柔 提交于 2019-12-05 18:50:12
问题 The title says it all. What I imagine is to have docstrings for all of my modules, classes and functions and somehow nicely navigate the doc via github (wiki?). Also, the doc should be in sync with latest code meaning it should be updated/re-generated on push. Is that possible? 回答1: Just pipe the output of the docstring to a .md file. Like this: pydoc 'example_lib > example_lib.md . 来源: https://stackoverflow.com/questions/29660467/automatically-generate-github-wiki-documentation-from-python

Referencing parameters in a Python docstring

核能气质少年 提交于 2019-12-05 16:57:32
问题 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

python rtype docstring/restructured text for class factories/selectors

爷,独闯天下 提交于 2019-12-05 02:35:31
:rtype: specifies that this is type of returned object Therefore, when I create object obj in following snippet I receive warning from IDE, that cls is not callable , since IDE expects, that cls is object of type SomeAbstractClass , and I want SomeAbstractClass itself IDE is right, since this is default behaviour. But how can I specify, that I am returning class, not instance of class? Specifying type instead of SomeAbstractClass helps a bit, but not a solution, since no further introspection available. def class_selector(data): """ :rtype: SomeAbstractClass :return: Return some class based on

Formatting python docstrings for dicts

大憨熊 提交于 2019-12-05 00:12:14
What's the recommended way of adding a docstring for a dictionary parameter? I can see multiple line docstring examples here . I need to document the input arguments to a function in the docstring. If it's a simple variable, I can use something like: def func2(a=x, b = y): """ fun2 takes two integers Keyword arguments: a -- refers to age (default 18) b -- refers to experience (default 0) """ If we have dict passed as input argument to function: def func3(**kwargs): """ takes dictionary as input <Here how to explain them - Is it like?> kwargs['key1'] -- takes value1 <or simply> key1 -- takes

How to stop PyCharm from populating docstrings?

拟墨画扇 提交于 2019-12-04 19:49:06
问题 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

How to specify different return types in python docstring

坚强是说给别人听的谎言 提交于 2019-12-04 05:10:58
I'm currently writing documentation for my python package using Sphinx and the autodoc plugin. For a function return value I can e.g. write :returns: int: count which tells sphinx that there is a return value of type int, named count. I now got a function which gets me predecessors of items in my database: def get_previous_release(release_id): """ Holt Vorgängeritem eines Items mit der ID release_id :param release_id: ID des items für das Release :type release_id: int """ if not isinstance(release_id, int): raise ValueError('get_previous_release expects an Integer value for the parameter

Setting the docstring to an expression inside def

那年仲夏 提交于 2019-12-04 03:58:26
问题 I would like to set the func_doc (as an expression) within def . def f(): '''My function help''' #Set the docstring def g(): "My function " + "help" # An expression, so not read as a docstring # can I put something here to set the docstring as an expression? g.func_doc # is None g.func_doc = "My function " + "help" # This works Is this possible? (two reasons I can think for doing this: importing a function from a module (and you want to import the docstring too) and using a lexer.) 回答1: You

Automatically Generate GitHub Wiki Documentation from Python Docstrings

感情迁移 提交于 2019-12-04 03:55:22
The title says it all. What I imagine is to have docstrings for all of my modules, classes and functions and somehow nicely navigate the doc via github (wiki?). Also, the doc should be in sync with latest code meaning it should be updated/re-generated on push. Is that possible? Kevin Gray Just pipe the output of the docstring to a .md file. Like this: pydoc 'example_lib > example_lib.md . 来源: https://stackoverflow.com/questions/29660467/automatically-generate-github-wiki-documentation-from-python-docstrings