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:
- docstring
- implements()
- class attributes
- Python special methods, starting with __new__ if present, then __init__.
- Methods part of no interface
- Methods implementing an interface, grouped by interface, prefixed with a comment like this:
# IYourInterface
- Be careful with code like:
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.
def test(): outer1, outer2 = something() class Stub(object): foo = frob(outer1) def bar(self): return outer2
Vulnerable names should be renamed to avoid conflict. Vulnerable values require wrapping in an indirect reference, such as:See also #2394.class Foo(formless.TypedInterface): pass _indirectFoo = lambda: Foo class Bar(formless.TypedInterface): baz = formless.Object(interface=_indirectFoo())
