From 33fcd393ab10a471dca99427e060c6f0f9b178fc Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 25 Jan 2020 13:55:27 +0900 Subject: Fix #6785: py domain: :py:attr: is able to refer properties again --- sphinx/domains/python.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'sphinx/domains/python.py') diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 777865b4b..242ef83c0 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -1011,6 +1011,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: -- cgit v1.2.1 From 179a1f9cc2832f2abc24c0e574f86f4aa6e7e632 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 30 Jan 2020 13:09:10 +0900 Subject: py domain: Support type annotations for variables This adds ``:type:`` and ``:value:`` options to both ``py:data`` and ``py:attribute`` directives. It allows to describe its annotation in detail. --- sphinx/domains/python.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'sphinx/domains/python.py') diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 777865b4b..b5ce9bdbf 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -446,6 +446,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: @@ -638,6 +657,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: -- cgit v1.2.1