-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcoding-standard.txt
40 lines (37 loc) · 1.6 KB
/
coding-standard.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
= Divmod Coding Standard =
Divmod uses [http://twistedmatrix.com/trac/browser/trunk/doc/development/policy/coding-standard.xhtml?format=raw 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
1. {{{implements()}}}
1. class attributes
1. Python special methods, starting with {{{__new__}}} if present, then {{{__init__}}}.
1. Methods part of no interface
1. Methods implementing an interface, grouped by interface, prefixed with a comment like this:
{{{
#!python
# IYourInterface
}}}
* Be careful with code like:
{{{
#!python
def test():
outer1, outer2 = something()
class Stub(object):
foo = frob(outer1)
def bar(self):
return outer2
}}}
Due to [http://bugs.python.org/issue1569356 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.[[BR]]
Vulnerable names should be renamed to avoid conflict. Vulnerable ''values'' require wrapping in an indirect reference, such as:
{{{
#!python
class Foo(formless.TypedInterface):
pass
_indirectFoo = lambda: Foo
class Bar(formless.TypedInterface):
baz = formless.Object(interface=_indirectFoo())
}}}
See also #2394.