mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-10-14 17:32:12 -05:00
This commit ensures that the ``__annotations__`` dict of a class is updated only with type comment-derived annotations for direct members; the type comment-derived annotations for parent classes are added to those parent classes own ``__annotations__`` dicts. The inherited member annotations are still found by ``typing.get_type_hints``. This commit also improves the efficiency of incorporating the annotations found by the ``ModuleAnalyzer``. Previously, each call to ``_load_object_by_name`` for a data member or attribute would result in separately iterating over all attributes (including within classes) found by ModuleAnalyzer for the containing module, and in the case of classes, the containing modules of all parent classes. For modules with many members this cost could likely be significant. With this commit, at least for the purpose of updating ``__annotations__`` dicts, each module's attributes only processed a single time in total. Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>