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

py3.9 support cleanup in sage_autodoc and sphinx bump #39577

Merged
merged 2 commits into from
Feb 28, 2025
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: 2 additions & 2 deletions build/pkgs/sphinx/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=sphinx-VERSION-py3-none-any.whl
sha1=f9af5608fbb188f12e38d3c09cdefeef40255365
sha256=c2419e2135d11f1951cd994d6eb18a1835bd8fdd8429f9ca375dc1f3281bd239
sha1=67dc18611c44f712539585db41aaee4b0a7ec646
sha256=09719015511837b76bf6e03e42eb7595ac8c2e41eeb9c29c5b755c6b677992a2
upstream_url=https://files.pythonhosted.org/packages/py3/s/sphinx/sphinx-VERSION-py3-none-any.whl
2 changes: 1 addition & 1 deletion build/pkgs/sphinx/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.4.7
8.1.3
63 changes: 14 additions & 49 deletions src/sage_docbuild/ext/sage_autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
- François Bissey (2024-09-10): Tweaks to support python 3.9 (and older sphinx) as well

- François Bissey (2024-11-12): rebased on Sphinx 8.1.3 (while trying to keep python 3.9 compatibility)

- François Bissey (2025-02-24): Remove python 3.9 support hacks, making us closer to upstream
"""

from __future__ import annotations

import functools
import operator
import sys
import re
from inspect import Parameter, Signature
from typing import TYPE_CHECKING, Any, NewType, TypeVar
Expand Down Expand Up @@ -709,7 +710,7 @@ def add_content(self, more_content: StringList | None) -> None:

# add additional content (e.g. from document), if present
if more_content:
for line, src in zip(more_content.data, more_content.items):
for line, src in zip(more_content.data, more_content.items, strict=True):
self.add_line(line, src[0], src[1])

def get_object_members(self, want_all: bool) -> tuple[bool, list[ObjectMember]]:
Expand Down Expand Up @@ -1080,7 +1081,7 @@ def add_content(self, more_content: StringList | None) -> None:
super().add_content(None)
self.indent = old_indent
if more_content:
for line, src in zip(more_content.data, more_content.items):
for line, src in zip(more_content.data, more_content.items, strict=True):
self.add_line(line, src[0], src[1])

@classmethod
Expand Down Expand Up @@ -1616,14 +1617,8 @@ def __init__(self, *args: Any) -> None:
def can_document_member(
cls: type[Documenter], member: Any, membername: str, isattr: bool, parent: Any,
) -> bool:
# support both sphinx 8 and py3.9/older sphinx
try:
result_bool = isinstance(member, type) or (
isattr and isinstance(member, NewType | TypeVar))
except Exception:
result_bool = isinstance(member, type) or (
isattr and (inspect.isNewType(member) or isinstance(member, TypeVar)))
return result_bool
return isinstance(member, type) or (
isattr and isinstance(member, NewType | TypeVar))

def import_object(self, raiseerror: bool = False) -> bool:
ret = super().import_object(raiseerror)
Expand Down Expand Up @@ -1696,12 +1691,7 @@ def import_object(self, raiseerror: bool = False) -> bool:
# -------------------------------------------------------------------
else:
self.doc_as_attr = True
# support both sphinx 8 and py3.9/older sphinx
try:
test_bool = isinstance(self.object, NewType | TypeVar)
except Exception:
test_bool = inspect.isNewType(self.object) or isinstance(self.object, TypeVar)
if test_bool:
if isinstance(self.object, NewType | TypeVar):
modname = getattr(self.object, '__module__', self.modname)
if modname != self.modname and self.modname.startswith(modname):
bases = self.modname[len(modname):].strip('.').split('.')
Expand All @@ -1710,12 +1700,7 @@ def import_object(self, raiseerror: bool = False) -> bool:
return ret

def _get_signature(self) -> tuple[Any | None, str | None, Signature | None]:
# support both sphinx 8 and py3.9/older sphinx
try:
test_bool = isinstance(self.object, NewType | TypeVar)
except Exception:
test_bool = inspect.isNewType(self.object) or isinstance(self.object, TypeVar)
if test_bool:
if isinstance(self.object, NewType | TypeVar):
# Suppress signature
return None, None, None

Expand Down Expand Up @@ -1900,24 +1885,14 @@ def add_directive_header(self, sig: str) -> None:
self.directivetype = 'attribute'
super().add_directive_header(sig)

# support both sphinx 8 and py3.9/older sphinx
try:
test_bool = isinstance(self.object, NewType | TypeVar)
except Exception:
test_bool = inspect.isNewType(self.object) or isinstance(self.object, TypeVar)
if test_bool:
if isinstance(self.object, NewType | TypeVar):
return

if self.analyzer and '.'.join(self.objpath) in self.analyzer.finals:
self.add_line(' :final:', sourcename)

canonical_fullname = self.get_canonical_fullname()
# support both sphinx 8 and py3.9/older sphinx
try:
newtype_test = isinstance(self.object, NewType)
except Exception:
newtype_test = inspect.isNewType(self.object)
if (not self.doc_as_attr and not newtype_test
if (not self.doc_as_attr and not isinstance(self.object, NewType)
and canonical_fullname and self.fullname != canonical_fullname):
self.add_line(' :canonical: %s' % canonical_fullname, sourcename)

Expand Down Expand Up @@ -2032,12 +2007,7 @@ def get_variable_comment(self) -> list[str] | None:
return None

def add_content(self, more_content: StringList | None) -> None:
# support both sphinx 8 and py3.9/older sphinx
try:
newtype_test = isinstance(self.object, NewType)
except Exception:
newtype_test = inspect.isNewType(self.object)
if newtype_test:
if isinstance(self.object, NewType):
if self.config.autodoc_typehints_format == "short":
supertype = restify(self.object.__supertype__, "smart")
else:
Expand Down Expand Up @@ -3006,14 +2976,9 @@ def _get_property_getter(self) -> Callable | None:

def autodoc_attrgetter(app: Sphinx, obj: Any, name: str, *defargs: Any) -> Any:
"""Alternative getattr() for types"""
try:
for typ, func in app.registry.autodoc_attrgetters.items():
if isinstance(obj, typ):
return func(obj, name, *defargs)
except AttributeError:
for typ, func in app.registry.autodoc_attrgettrs.items():
if isinstance(obj, typ):
return func(obj, name, *defargs)
for typ, func in app.registry.autodoc_attrgetters.items():
if isinstance(obj, typ):
return func(obj, name, *defargs)

return safe_getattr(obj, name, *defargs)

Expand Down
Loading