summaryrefslogtreecommitdiff
path: root/doc/build/lib/docstring.py
diff options
context:
space:
mode:
authorJason Kirtland <jek@discorporate.us>2007-08-01 17:51:10 +0000
committerJason Kirtland <jek@discorporate.us>2007-08-01 17:51:10 +0000
commit2f14107999bc047531c78caecb62a35f6daf9b5f (patch)
tree1df22cedc155294dcf52a5988b1d4bab58dfd60f /doc/build/lib/docstring.py
parentf8ebf35deb4864826b6bc1789223e2a42e6edf96 (diff)
downloadsqlalchemy-2f14107999bc047531c78caecb62a35f6daf9b5f.tar.gz
Sort methods by __init__, name, __names__
Supply a little default docstring for __init__ Don't document __repr__, __str__, __getstate__, ...
Diffstat (limited to 'doc/build/lib/docstring.py')
-rw-r--r--doc/build/lib/docstring.py40
1 files changed, 31 insertions, 9 deletions
diff --git a/doc/build/lib/docstring.py b/doc/build/lib/docstring.py
index 441aed900..819296ccf 100644
--- a/doc/build/lib/docstring.py
+++ b/doc/build/lib/docstring.py
@@ -60,7 +60,7 @@ class ObjectDoc(AbstractDoc):
not self._is_private_name(x)
]
)
- functions.sort(lambda a, b: cmp(getattr(a, '__name__', None) or a[0], getattr(b, '__name__', None) or b[0] ))
+ functions.sort(_method_sort)
if classes is None:
classes = []
@@ -86,23 +86,24 @@ class ObjectDoc(AbstractDoc):
self.doc = obj.__doc__
self.functions = []
- if not self.isclass and len(functions):
+ if not self.isclass:
for func in functions:
self.functions.append(FunctionDoc(func))
else:
- if len(functions):
- for func in functions:
- if isinstance(func, types.FunctionType):
- self.functions.append(FunctionDoc(func))
- elif isinstance(func, tuple):
- self.functions.append(PropertyDoc(func[0], func[1]))
+ for func in functions:
+ if isinstance(func, types.FunctionType):
+ self.functions.append(MethodDoc(func, self))
+ elif isinstance(func, tuple):
+ self.functions.append(PropertyDoc(func[0], func[1]))
self.classes = []
for class_ in classes:
self.classes.append(ObjectDoc(class_))
def _is_private_name(self, name):
- if name == '__weakref__':
+ if name in ('__weakref__', '__repr__','__str__', '__unicode__',
+ '__getstate__', '__setstate__', '__reduce__',
+ '__reduce_ex__', '__hash__'):
return True
elif re.match(r'^__.*__$', name):
return False
@@ -149,6 +150,12 @@ class FunctionDoc(AbstractDoc):
def accept_visitor(self, visitor):
visitor.visit_function(self)
+class MethodDoc(FunctionDoc):
+ def __init__(self, func, owner):
+ super(MethodDoc, self).__init__(func)
+ if self.name == '__init__' and not self.doc:
+ self.doc = "Construct a new ``%s``." % owner.name
+
class PropertyDoc(AbstractDoc):
def __init__(self, name, prop):
super(PropertyDoc, self).__init__(prop)
@@ -157,3 +164,18 @@ class PropertyDoc(AbstractDoc):
self.link = name
def accept_visitor(self, visitor):
visitor.visit_property(self)
+
+def _method_sort(fna, fnb):
+ a = getattr(fna, '__name__', None) or fna[0]
+ b = getattr(fnb, '__name__', None) or fnb[0]
+
+ if a == '__init__': return -1
+ if b == '__init__': return 1
+
+ a_u = a.startswith('__') and a.endswith('__')
+ b_u = b.startswith('__') and b.endswith('__')
+
+ if a_u and not b_u: return 1
+ if b_u and not a_u: return -1
+
+ return cmp(a, b)