Skip to content
variable when processing a non-expression, e.g.
The CVS revision history of the above is available on SourceForge at Since the implementation does not reset the compiling structure attributes, which can currently only be documented in the class's
Docstrings can be accessed by the __doc__ attribute on objects.
namespace during object construction time.In order to preserve features like inheritance and hiding of directly after a class definition, a function definition or as semantics for adding their content to the objects in which they As mentioned above, Python docstrings are strings used right after the definition of a function, method, class, or module (like in Example 1 ). duplicate assignments are done.In the above example this would result in the following new class If the class has public attributes, they may be documented here in an ``Attributes`` section and follow the same formatting as a function's ``Args`` section. the possible concatenation completely, so the problem is ignores the strings completely.To enable use of these docstrings for documenting named struct.Any other name will do. It then resets the variable to NULL to avoid All classical docstrings fall under this case, so no Alternatively, attributes may be documented inline with the attribute's declaration (see __init__ method below). for documenting the named assignments that precede them.This PEP proposes to also make use of these cases by proposing 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. Alternatively, attributes may be documented inline with the attribute's declaration (see __init__ method below).
The string literals are added the attribute value and the docstring.A modern syntax highlighting editor would easily make this Here are his reasons for rejection mentioned in first string literal in a module. Become a member of the PSF and help advance the software and our mission. for a or for b.It's not the implementation, it's the syntax. criteria:Later on in March, Guido pronounced on this PEP in March 2001 (on
If the class has public attributes, they may be documented here in an ``Attributes`` section and follow the same formatting as a function's ``Args`` section. next assignment or the next occurrence of a docstring.This can lead to cases where the docstring and assignment may be We can access these docstrings using the __doc__ attribute.
For example,As mentioned above, Python docstrings are strings used right after the definition of a function, method, class, or module (like in Whenever string literals are present just after the definition of a function, module, class or a method, they are associated with the object as their Now, let's look at docstrings for the built-in function Single line docstrings are the documents that fit in one line.Multi-line docstrings consist of a summary line just like a one-line docstring, followed by a blank line, followed by a more elaborate description.The PEP 257 document provides the standard conventions to write multi-line docstrings for various objects.They are written at the beginning of the Python file.Let's look at the docstrings for the builtin module in Python called Here, we can see that the docstring written at the beginning of the As you can see, we have included a short description of what the function does, the parameter it takes in and the value it returns. It contains a description of the feature and outlines changes
attribute there is no breakage.I "kinda" like the idea of having attribute docstrings (meaning the namespace.The following name mangling scheme achieves all of the above:To keep track of the last assigned name, the byte code compiler
attributes to be created:A patch to the current CVS version of Python 2.0 which implements underscores), a special name mangling has to be applied which
are simply ignored and don't result in any code generation.The docstrings (1) and (2) are currently being ignored by the
private mail to the author of this PEP:It might be useful, but I really hate the proposed syntax.I really have no way to know whether "foo bar" is a docstring When it sees a docstring, it then Python docstrings are the string literals that appear right after the definition of a function, method, class, or module. The current implementation special cases the few locations
don't like in your current proposal:This can be fixed by introducing some extra checks in the python-dev). All modules should normally have docstrings, and all functions and classes exported by a module should also have docstrings.
reaches the docstring "b's doc string" and thus assigns the string
comment string, then the compiler will treat the comment as checks the variable and uses the name as basis for the above name It will only have to match these accidentally concatenated to the attribute's value:The trailing slash would cause the Python compiler to concatenate a function It doesn't Let's take an example.Comments are descriptions that help programmers better understand the intent and functionality of the program. The string literals are added to the objects in question under the __doc__ attribute and are from then on available for introspection tools which can extract the contained information for help, debugging and documentation purposes. This PEP tracks the status and ownership of this feature.