From 70277dfed7b06d0ecfa87a2e6b907bfb22d51268 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 26 Aug 2023 13:13:05 +0100 Subject: [PATCH 1/2] extract from try/except --- sphinx/ext/autodoc/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index c042aa71a7f..6b568457d71 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -675,12 +675,12 @@ def is_filtered_inherited_member(name: str, obj: Any) -> bool: # process members and determine which to skip for obj in members: - try: - membername = obj.__name__ - member = obj.object - # if isattr is True, the member is documented as an attribute - isattr = member is INSTANCEATTR or (namespace, membername) in attr_docs + membername = obj.__name__ + member = obj.object + # if isattr is True, the member is documented as an attribute + isattr = member is INSTANCEATTR or (namespace, membername) in attr_docs + try: doc = getdoc(member, self.get_attr, self.config.autodoc_inherit_docstrings, self.object, membername) if not isinstance(doc, str): From 8f2a6f044fbd456f6fa224cf5435b652ef72ad19 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 27 Aug 2023 22:51:11 +0100 Subject: [PATCH 2/2] Warn when a tuple is returned as an object --- sphinx/ext/autodoc/__init__.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 6b568457d71..ac1b5cec6f6 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -675,8 +675,22 @@ def is_filtered_inherited_member(name: str, obj: Any) -> bool: # process members and determine which to skip for obj in members: - membername = obj.__name__ - member = obj.object + try: + membername = obj.__name__ + member = obj.object + except AttributeError: + if isinstance(obj, ObjectMember): + raise + # To be removed, retained for compatibility. + # See https://github.com/sphinx-doc/sphinx/issues/11631 + membername, member = obj + warnings.warn( + 'Returning tuples of (name, object) as ' + 'the second return value from get_object_members() is deprecated. ' + 'Return ObjectMember(name, object) instances instead.', + RemovedInSphinx80Warning, stacklevel=2, + ) + # if isattr is True, the member is documented as an attribute isattr = member is INSTANCEATTR or (namespace, membername) in attr_docs