|
81 | 81 | from sphinx.util import logging, rst
|
82 | 82 | from sphinx.util.docutils import (NullReporter, SphinxDirective, SphinxRole, new_document,
|
83 | 83 | switch_source_input)
|
84 |
| -from sphinx.util.inspect import signature_from_str |
| 84 | +from sphinx.util.inspect import signature_from_str, getmro |
85 | 85 | from sphinx.util.matching import Matcher
|
86 | 86 | from sphinx.util.typing import OptionSpec
|
87 | 87 | from sphinx.writers.html import HTMLTranslator
|
@@ -711,15 +711,20 @@ def import_ivar_by_name(name: str, prefixes: List[str] = [None],
|
711 | 711 | try:
|
712 | 712 | name, attr = name.rsplit(".", 1)
|
713 | 713 | real_name, obj, parent, modname = import_by_name(name, prefixes, grouped_exception)
|
714 |
| - qualname = real_name.replace(modname + ".", "") |
715 |
| - analyzer = ModuleAnalyzer.for_module(getattr(obj, '__module__', modname)) |
716 |
| - analyzer.analyze() |
717 |
| - # check for presence in `annotations` to include dataclass attributes |
718 |
| - attrs_found = {name_attr[1] for name_attr in analyzer.attr_docs} | { |
719 |
| - name_attr[1] for name_attr in analyzer.annotations |
720 |
| - } |
721 |
| - if attr in attrs_found: |
722 |
| - return real_name + "." + attr, INSTANCEATTR, obj, modname |
| 714 | + |
| 715 | + candidate_objects = getmro(obj) |
| 716 | + if len(candidate_objects) == 0: |
| 717 | + candidate_objects = (obj,) |
| 718 | + |
| 719 | + for candidate_obj in candidate_objects: |
| 720 | + analyzer = ModuleAnalyzer.for_module(getattr(candidate_obj, '__module__', modname)) |
| 721 | + analyzer.analyze() |
| 722 | + # check for presence in `annotations` to include dataclass attributes |
| 723 | + attrs_found = {name_attr[1] for name_attr in analyzer.attr_docs} | { |
| 724 | + name_attr[1] for name_attr in analyzer.annotations |
| 725 | + } |
| 726 | + if attr in attrs_found: |
| 727 | + return real_name + "." + attr, INSTANCEATTR, obj, modname |
723 | 728 | except (ImportError, ValueError, PycodeError) as exc:
|
724 | 729 | raise ImportError from exc
|
725 | 730 | except ImportExceptionGroup:
|
|
0 commit comments