diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-02-09 00:57:53 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-02-09 00:57:53 +0900 |
commit | 2e87ee85a22279ee4ecc658f830520a88c90236d (patch) | |
tree | 124b080e0203aead764362ba1e5bd11da62822e5 /sphinx/domains/python.py | |
parent | d4aeae475943aef9b935f7487baf90ccc1c58b42 (diff) | |
parent | 1e5342faa9147c7a3c60e41dc7671e88f6795855 (diff) | |
download | sphinx-git-2e87ee85a22279ee4ecc658f830520a88c90236d.tar.gz |
Merge branch '2.0'
Diffstat (limited to 'sphinx/domains/python.py')
-rw-r--r-- | sphinx/domains/python.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 3c3d3d707..1b551c70b 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -437,6 +437,25 @@ class PyFunction(PyObject): class PyVariable(PyObject): """Description of a variable.""" + option_spec = PyObject.option_spec.copy() + option_spec.update({ + 'type': directives.unchanged, + 'value': directives.unchanged, + }) + + def handle_signature(self, sig: str, signode: desc_signature) -> Tuple[str, str]: + fullname, prefix = super().handle_signature(sig, signode) + + typ = self.options.get('type') + if typ: + signode += addnodes.desc_annotation(typ, ': ' + typ) + + value = self.options.get('value') + if value: + signode += addnodes.desc_annotation(value, ' = ' + value) + + return fullname, prefix + def get_index_text(self, modname: str, name_cls: Tuple[str, str]) -> str: name, cls = name_cls if modname: @@ -629,6 +648,25 @@ class PyStaticMethod(PyMethod): class PyAttribute(PyObject): """Description of an attribute.""" + option_spec = PyObject.option_spec.copy() + option_spec.update({ + 'type': directives.unchanged, + 'value': directives.unchanged, + }) + + def handle_signature(self, sig: str, signode: desc_signature) -> Tuple[str, str]: + fullname, prefix = super().handle_signature(sig, signode) + + typ = self.options.get('type') + if typ: + signode += addnodes.desc_annotation(typ, ': ' + typ) + + value = self.options.get('value') + if value: + signode += addnodes.desc_annotation(value, ' = ' + value) + + return fullname, prefix + def get_index_text(self, modname: str, name_cls: Tuple[str, str]) -> str: name, cls = name_cls try: @@ -1017,6 +1055,11 @@ class PythonDomain(Domain): searchmode = 1 if node.hasattr('refspecific') else 0 matches = self.find_obj(env, modname, clsname, target, type, searchmode) + + if not matches and type == 'attr': + # fallback to meth (for property) + matches = self.find_obj(env, modname, clsname, target, 'meth', searchmode) + if not matches: return None elif len(matches) > 1: |