Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build with sphinx 7 #35658

Merged
merged 6 commits into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/sage_docbuild/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ def set_intersphinx_mappings(app, config):
app.config.intersphinx_mapping['sagemath'] = (refpath, dst)

# Add intersphinx mapping for subdirectories
# We intentionally do not name these such that these get higher
# priority in case of conflicts
for directory in os.listdir(os.path.join(invpath)):
if directory == 'jupyter_execute':
# This directory is created by jupyter-sphinx extension for
Expand All @@ -248,7 +246,7 @@ def set_intersphinx_mappings(app, config):
if os.path.isdir(os.path.join(invpath, directory)):
src = os.path.join(refpath, directory)
dst = os.path.join(invpath, directory, 'objects.inv')
app.config.intersphinx_mapping[src] = dst
app.config.intersphinx_mapping[directory] = (src, dst)

antonio-rojas marked this conversation as resolved.
Show resolved Hide resolved
intersphinx.normalize_intersphinx_mapping(app, config)

Expand Down
59 changes: 17 additions & 42 deletions src/sage_docbuild/ext/sage_autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- Kwankyu Lee (2018-12-26, 2022-11-08): rebased on the latest sphinx.ext.autodoc

"""
from __future__ import annotations

import re
import warnings
Expand All @@ -44,7 +45,6 @@
import sphinx
from sphinx.application import Sphinx
from sphinx.config import ENUM, Config
from sphinx.deprecation import RemovedInSphinx60Warning
from sphinx.environment import BuildEnvironment
from sphinx.ext.autodoc.importer import (get_class_members, get_object_members, import_module,
import_object)
Expand All @@ -56,7 +56,11 @@
from sphinx.util.inspect import (evaluate_signature, getdoc, object_description, safe_getattr,
stringify_signature)
from sphinx.util.typing import OptionSpec, get_type_hints, restify
from sphinx.util.typing import stringify as stringify_typehint

try:
from sphinx.util.typing import stringify_annotation
except ImportError:
from sphinx.util.typing import stringify as stringify_annotation

# ------------------------------------------------------------------
antonio-rojas marked this conversation as resolved.
Show resolved Hide resolved
from sage.misc.sageinspect import (sage_getdoc_original,
Expand Down Expand Up @@ -646,32 +650,13 @@ def add_content(self, more_content: Optional[StringList]) -> None:
self.add_line(line, src[0], src[1])

def get_object_members(self, want_all: bool) -> Tuple[bool, ObjectMembers]:
"""Return ``(members_check_module, members)`` where ``members`` is a
list of ``(membername, member)`` pairs of the members of *self.object*.
"""Return `(members_check_module, members)` where `members` is a
list of `(membername, member)` pairs of the members of *self.object*.

If *want_all* is True, return all members. Else, only return those
members given by *self.options.members* (which may also be None).
"""
warnings.warn('The implementation of Documenter.get_object_members() will be '
'removed from Sphinx-6.0.', RemovedInSphinx60Warning)
members = get_object_members(self.object, self.objpath, self.get_attr, self.analyzer)
if not want_all:
if not self.options.members:
return False, [] # type: ignore
# specific members given
selected = []
for name in self.options.members:
if name in members:
selected.append((name, members[name].value))
else:
logger.warning(__('missing attribute %s in object %s') %
(name, self.fullname), type='autodoc')
return False, selected
elif self.options.inherited_members:
return False, [(m.name, m.value) for m in members.values()]
else:
return False, [(m.name, m.value) for m in members.values()
if m.directly_defined]
raise NotImplementedError('must be implemented in subclasses')

def filter_members(self, members: ObjectMembers, want_all: bool
antonio-rojas marked this conversation as resolved.
Show resolved Hide resolved
) -> List[Tuple[str, Any, bool]]:
Expand Down Expand Up @@ -2050,9 +2035,9 @@ def update_content(self, more_content: StringList) -> None:
attrs = [repr(self.object.__name__)]
for constraint in self.object.__constraints__:
if self.config.autodoc_typehints_format == "short":
attrs.append(stringify_typehint(constraint, "smart"))
attrs.append(stringify_annotation(constraint, "smart"))
else:
attrs.append(stringify_typehint(constraint))
attrs.append(stringify_annotation(constraint))
if self.object.__bound__:
if self.config.autodoc_typehints_format == "short":
bound = restify(self.object.__bound__, "smart")
Expand Down Expand Up @@ -2175,10 +2160,10 @@ def add_directive_header(self, sig: str) -> None:
self.config.autodoc_type_aliases)
if self.objpath[-1] in annotations:
if self.config.autodoc_typehints_format == "short":
objrepr = stringify_typehint(annotations.get(self.objpath[-1]),
objrepr = stringify_annotation(annotations.get(self.objpath[-1]),
"smart")
else:
objrepr = stringify_typehint(annotations.get(self.objpath[-1]))
objrepr = stringify_annotation(annotations.get(self.objpath[-1]))
self.add_line(' :type: ' + objrepr, sourcename)

try:
Expand Down Expand Up @@ -2494,16 +2479,6 @@ def get_doc(self) -> Optional[List[List[str]]]:
else:
return super().get_doc() # type: ignore

@property
def _datadescriptor(self) -> bool:
warnings.warn('AttributeDocumenter._datadescriptor() is deprecated.',
RemovedInSphinx60Warning)
if self.object is SLOTSATTR:
return True
else:
return False


class RuntimeInstanceAttributeMixin(DataDocumenterMixinBase):
"""
Mixin for AttributeDocumenter to provide the feature for supporting runtime
Expand Down Expand Up @@ -2756,10 +2731,10 @@ def add_directive_header(self, sig: str) -> None:
self.config.autodoc_type_aliases)
if self.objpath[-1] in annotations:
if self.config.autodoc_typehints_format == "short":
objrepr = stringify_typehint(annotations.get(self.objpath[-1]),
objrepr = stringify_annotation(annotations.get(self.objpath[-1]),
"smart")
else:
objrepr = stringify_typehint(annotations.get(self.objpath[-1]))
objrepr = stringify_annotation(annotations.get(self.objpath[-1]))
self.add_line(' :type: ' + objrepr, sourcename)

try:
Expand Down Expand Up @@ -2884,9 +2859,9 @@ def add_directive_header(self, sig: str) -> None:
type_aliases=self.config.autodoc_type_aliases)
if signature.return_annotation is not Parameter.empty:
if self.config.autodoc_typehints_format == "short":
objrepr = stringify_typehint(signature.return_annotation, "smart")
objrepr = stringify_annotation(signature.return_annotation, "smart")
else:
objrepr = stringify_typehint(signature.return_annotation)
objrepr = stringify_annotation(signature.return_annotation)
self.add_line(' :type: ' + objrepr, sourcename)
except TypeError as exc:
logger.warning(__("Failed to get a function signature for %s: %s"),
Expand Down