summaryrefslogtreecommitdiff
path: root/sphinx/domains/python.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/domains/python.py')
-rw-r--r--sphinx/domains/python.py43
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: