diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-04-13 20:25:07 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-04-13 20:26:07 +0900 |
commit | 6af38961036dbf05d9ff3c99ab8d39e8b2b5ec2a (patch) | |
tree | e013d61ccf885689b33858474f39fa10c45d7efd /sphinx/domains/python.py | |
parent | a337cb793cf067a94f498b8842d7bc3ad96a87b2 (diff) | |
download | sphinx-git-6af38961036dbf05d9ff3c99ab8d39e8b2b5ec2a.tar.gz |
Add PyFunction and PyVariable; directives for python functions and variables
Diffstat (limited to 'sphinx/domains/python.py')
-rw-r--r-- | sphinx/domains/python.py | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index de31eef00..898265f0b 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -410,6 +410,13 @@ class PyModulelevel(PyObject): Description of an object on module level (functions, data). """ + def run(self): + # type: () -> List[nodes.Node] + warnings.warn('PyClassmember is deprecated.', + RemovedInSphinx40Warning) + + return super().run() + def needs_arglist(self): # type: () -> bool return self.objtype == 'function' @@ -428,6 +435,34 @@ class PyModulelevel(PyObject): return '' +class PyFunction(PyObject): + """Description of a function.""" + + def needs_arglist(self): + # type: () -> bool + return True + + def get_index_text(self, modname, name_cls): + # type: (str, Tuple[str, str]) -> str + name, cls = name_cls + if modname: + return _('%s() (in module %s)') % (name, modname) + else: + return _('%s() (built-in function)') % name + + +class PyVariable(PyObject): + """Description of a variable.""" + + def get_index_text(self, modname, name_cls): + # type: (str, Tuple[str, str]) -> str + name, cls = name_cls + if modname: + return _('%s (in module %s)') % (name, modname) + else: + return _('%s (built-in variable)') % name + + class PyClasslike(PyObject): """ Description of a class-like object (classes, interfaces, exceptions). @@ -839,8 +874,8 @@ class PythonDomain(Domain): } # type: Dict[str, ObjType] directives = { - 'function': PyModulelevel, - 'data': PyModulelevel, + 'function': PyFunction, + 'data': PyVariable, 'class': PyClasslike, 'exception': PyClasslike, 'method': PyMethod, |