summaryrefslogtreecommitdiffstats
path: root/Doc/tools
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-07-29 16:01:11 (GMT)
committerGeorg Brandl <georg@python.org>2010-07-29 16:01:11 (GMT)
commit8a1caa2361b86baeadfe5343b0c74fe9dec2a4ce (patch)
treea61437b150df841a5de65b9bb92456e0e3b4139a /Doc/tools
parentb0a4e3c1a747a1f40be0d0e4d2ab785b052673c2 (diff)
downloadcpython-8a1caa2361b86baeadfe5343b0c74fe9dec2a4ce.zip
cpython-8a1caa2361b86baeadfe5343b0c74fe9dec2a4ce.tar.gz
cpython-8a1caa2361b86baeadfe5343b0c74fe9dec2a4ce.tar.bz2
#6522: add a "decorator" directive to explicitly document decorators, and use it in a few places.
Diffstat (limited to 'Doc/tools')
-rw-r--r--Doc/tools/sphinxext/pyspecific.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/Doc/tools/sphinxext/pyspecific.py b/Doc/tools/sphinxext/pyspecific.py
index b7a6012..5ee35b0 100644
--- a/Doc/tools/sphinxext/pyspecific.py
+++ b/Doc/tools/sphinxext/pyspecific.py
@@ -72,6 +72,32 @@ class ImplementationDetail(Directive):
return [pnode]
+# Support for documenting decorators
+
+from sphinx import addnodes
+from sphinx.domains.python import PyModulelevel, PyClassmember
+
+class PyDecoratorMixin(object):
+ def handle_signature(self, sig, signode):
+ ret = super(PyDecoratorMixin, self).handle_signature(sig, signode)
+ signode.insert(0, addnodes.desc_addname('@', '@'))
+ return ret
+
+ def needs_arglist(self):
+ return False
+
+class PyDecoratorFunction(PyDecoratorMixin, PyModulelevel):
+ def run(self):
+ # a decorator function is a function after all
+ self.name = 'py:function'
+ return PyModulelevel.run(self)
+
+class PyDecoratorMethod(PyDecoratorMixin, PyClassmember):
+ def run(self):
+ self.name = 'py:method'
+ return PyClassmember.run(self)
+
+
# Support for building "topic help" for pydoc
pydoc_topic_labels = [
@@ -147,7 +173,6 @@ import suspicious
# Support for documenting Opcodes
import re
-from sphinx import addnodes
opcode_sig_re = re.compile(r'(\w+(?:\+\d)?)(?:\s*\((.*)\))?')
@@ -197,3 +222,5 @@ def setup(app):
app.add_description_unit('pdbcommand', 'pdbcmd', '%s (pdb command)',
parse_pdb_command)
app.add_description_unit('2to3fixer', '2to3fixer', '%s (2to3 fixer)')
+ app.add_directive_to_domain('py', 'decorator', PyDecoratorFunction)
+ app.add_directive_to_domain('py', 'decoratormethod', PyDecoratorMethod)