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