Divmod Coding Standard

Divmod uses the Twisted coding standard.

In addition, we are trying to make certain aspects of the Twisted coding standard stricter. For example:

  • There should be 3 blank lines between module-level suites, such as classes and top-level functions.
  • There should be 2 blank lines between class-level suites, such as methods.
  • Within a class, the ordering of the elements is:
    1. docstring
    2. implements()
    3. class attributes
    4. Python special methods, starting with __new__ if present, then __init__.
    5. Methods part of no interface
    6. Methods implementing an interface, grouped by interface, prefixed with a comment like this:
      # IYourInterface
      
      
  • Be careful with code like:
    def test():
        outer1, outer2 = something()
        class Stub(object):
            foo = frob(outer1)
            def bar(self):
                return outer2
    
    Due to a bug in Python ≤ 2.5, when run with tracing (such as trial --coverage), the closed bindings (outer1, outer2) leak into the class context, causing problems when they have special meaning there.
    Vulnerable names should be renamed to avoid conflict. Vulnerable values require wrapping in an indirect reference, such as:
        class Foo(formless.TypedInterface):
            pass
        _indirectFoo = lambda: Foo
        class Bar(formless.TypedInterface):
            baz = formless.Object(interface=_indirectFoo())
    
    See also #2394.
jethro@divmod.org