15
15
This document contains a style guide for Python programming, as used in GNU
16
16
Mailman. `PEP 8`_ is the basis for this style guide so it's recommendations
17
17
should be followed except for the differences outlined here. This document
18
assumes the use of Python 2.7, but not (yet) Python 3.
18
assumes the use of Python 3.
20
* After file comments (e.g. license block), add a ``__metaclass__`` definition
21
so that all classes will be new-style. Following that, add an ``__all__``
22
section that names, one-per-line, all the public names exported by this
23
module. You should enable absolute imports and unicode literals. See the
20
* After file comments (e.g. license block), add an ``__all__`` section that
21
names, one-per-line, all the public names exported by this module. See the
24
22
`GNU Mailman Python template`_ as an example.
26
24
* Imports are always put at the top of the file, just after any module
27
25
comments and docstrings, and before module globals and constants, but after
28
any ``__future__`` imports, or ``__metaclass__`` and ``__all__``
26
any ``__all__`` definitions.
31
28
Imports should be grouped, with the order being:
33
1. non-from imports for standard and third party libraries
34
2. non-from imports from the application
35
3. from-imports from the standard and third party libraries
36
4. from-imports from the application
38
From-imports should follow non-from imports. Dotted imports should follow
39
non-dotted imports. Non-dotted imports should be grouped by increasing
40
length, while dotted imports should be grouped alphabetically.
42
* In general, there should be one class per module. Keep files small, but
43
it's okay to group related code together. List everything exported from the
44
module in the ``__all__``.
30
1. non-from imports, grouped from shorted module name to longest module
31
name, with ties being broken by alphabetical order.
32
3. from-imports grouped alphabetically.
34
* In general, there should be one class per module. This is not a
35
hard-and-fast rule. Keep files small, but it's okay to group related code
36
together. List everything exported from the module in the ``__all__``.
46
38
* Right hanging comments are discouraged, in favor of preceding comments.