mirror of
https://github.com/python/cpython.git
synced 2025-09-14 20:56:06 +00:00
#6522: add a "decorator" directive to explicitly document decorators, and use it in a few places.
This commit is contained in:
parent
b0a4e3c1a7
commit
8a1caa2361
7 changed files with 75 additions and 16 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue