~barry/mailman/lp1423756

« back to all changes in this revision

Viewing changes to src/mailman/docs/STYLEGUIDE.rst

  • Committer: Barry Warsaw
  • Date: 2015-01-05 01:20:33 UTC
  • mfrom: (7264.4.66 py3)
  • Revision ID: barry@list.org-20150105012033-zdrw9c2odhpf22fz
Merge the Python 3 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
19
19
 
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.
25
23
 
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__``
29
 
  definitions.
 
26
  any ``__all__`` definitions.
30
27
 
31
28
  Imports should be grouped, with the order being:
32
29
 
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
37
 
 
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.
41
 
 
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.
 
33
 
 
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__``.
45
37
 
46
38
* Right hanging comments are discouraged, in favor of preceding comments.
47
39
  E.g. bad::