![]() ![]() code = code class ExampleClass : """The summary line for a class docstring should fit on one line. """ def _init_ ( self, msg, code ): self. Attributes: msg (str): Human readable string describing the exception. Args: msg (str): Human readable string describing the exception. Note: Do not include the `self` parameter in the ``Args`` section. Choose one convention to document the _init_ method and be consistent with it. Either form is acceptable, but the two should not be mixed. The _init_ method may be documented in either the class level docstring, or as a docstring on the _init_ method itself. > print() """ for i in range ( n ): yield i class ExampleError ( Exception ): """Exceptions are documented in the same way as classes. Examples: Examples should be written in doctest format, and should illustrate how to use the function. Yields: int: The next number in the range of 0 to `n` - 1. Args: n (int): The upper limit of the range to generate, from 0 to `n` - 1. """ if param1 = param2 : raise ValueError ( 'param1 may not be equal to param2' ) return True def example_generator ( n ): """Generators have a ``Yields`` section instead of a ``Returns`` section. ValueError: If `param2` is equal to `param1`. The ``Returns`` section supports any reStructuredText formatting, including literal blocks:: Raises: AttributeError: The ``Raises`` section is a list of all exceptions that are relevant to the interface. Following lines should be indented to match the first line. The ``Returns`` section may span multiple lines and paragraphs. The return type is optional and may be specified at the beginning of the ``Returns`` section followed by a colon. Returns: bool: True if successful, False otherwise. Second line of description should be indented. param2 (:obj:`str`, optional): The second parameter. Multiple paragraphs are supported in parameter descriptions. The format for a parameter is:: name (type): description The description may span multiple lines. If ``*args`` or ``**kwargs`` are accepted, they should be listed as ``*args`` and ``**kwargs``. The type and description of each parameter is optional, but should be included if not obvious. Function parameters should be documented in the ``Args`` section. """ def module_level_function ( param1, param2 = None, * args, ** kwargs ): """This is an example of a module level function. """ def function_with_pep484_type_annotations ( param1 : int, param2 : str ) -> bool : """Example function with PEP 484 type annotations. If attribute, parameter, and return types are annotated according to `PEP 484`_, they do not need to be included in the docstring: Args: param1 (int): The first parameter. :pep:`484` type annotations are supported. """ def function_with_types_in_docstring ( param1, param2 ): """Example function with types documented in the docstring. ![]() The type may optionally be specified on the first line, separated by a colon. _Google Python Style Guide: """ module_level_variable1 = 12345 module_level_variable2 = 98765 """int: Module level variable documented inline. Todo: * For module TODOs * You have to also use ```` extension. Choose one convention to document module level variables and be consistent with it. Attributes: module_level_variable1 (int): Module level variables may be documented in either the ``Attributes`` section of the module docstring, or in an inline docstring immediately following the variable. Section breaks are also implicitly created anytime a new section starts. Sections support any reStructuredText formatting, including literal blocks:: $ python example_google.py Section breaks are created by resuming unindented text. Example: Examples can be given using either the ``Example`` or ``Examples`` sections. Sections are created with a section header and a colon followed by a block of indented text. ![]() Docstrings may extend over multiple lines. This module demonstrates documentation as specified by the `Google Python Style Guide`_. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |