|
| 1 | +The D1xx group of errors deals with missing docstring in public constructs: |
| 2 | +modules, classes, methods, etc. It is important to note how publicity is |
| 3 | +determined and what its effects are. |
| 4 | + |
| 5 | + |
| 6 | +How publicity is determined |
| 7 | +=========================== |
| 8 | + |
| 9 | +Publicity for all constructs is determined as follows: a construct is |
| 10 | +considered *public* if - |
| 11 | + |
| 12 | +1. Its immediate parent is public *and* |
| 13 | +2. Its name does not contain a single leading underscore. |
| 14 | + |
| 15 | +A construct's immediate parent is the construct that contains it. For example, |
| 16 | +a method's parent is a class object. A class' parent is usually a module, but |
| 17 | +might also be a function, method, etc. A module can either have no parent, or |
| 18 | +it can have a parent that is a package. |
| 19 | + |
| 20 | +In order for a construct to be considered public, its immediate parent must |
| 21 | +also be public. Since this definition is recursive, it means that *all* of its |
| 22 | +parents need to be public. The corollary is that if a construct is considered |
| 23 | +private, then all of its descendants are also considered private. For example, |
| 24 | +a class called ``_Foo`` is considered private. A method ``bar`` in ``_Foo`` is |
| 25 | +also considered private since its parent is a private class, even though its |
| 26 | +name does not begin with a single underscore. |
| 27 | + |
| 28 | + |
| 29 | +How publicity affects error reports |
| 30 | +=================================== |
| 31 | + |
| 32 | +The immediate effect of a construct being determined as private is that no |
| 33 | +D1xx errors will be reported for it (or its children, as the previous section |
| 34 | +explains). A private method, for instance, will not generate a D102 error, even |
| 35 | +if it has no docstring. |
| 36 | + |
| 37 | +However, it is important to note that while docstring are optional for private |
| 38 | +construct, they are still required to adhere to your style guide. So if a |
| 39 | +private module `_foo.py` does not have a docstring, it will not generate a |
| 40 | +D100 error, but if it *does* have a docstring, that docstring might generate |
| 41 | +other errors. |
0 commit comments