Skip to content

Commit 3918083

Browse files
author
Release Manager
committed
gh-39577: py3.9 support cleanup in sage_autodoc and sphinx bump This is a follow up to #39251 This PR removes work around to support older python during the last two synchronization of sage_autodoc.py with upstream. python 3.9/3.10 support removal also enable us to move to a newer version of sphinx. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #39577 Reported by: François Bissey Reviewer(s): Kwankyu Lee
2 parents a8f16cf + dabc390 commit 3918083

File tree

3 files changed

+17
-52
lines changed

3 files changed

+17
-52
lines changed

build/pkgs/sphinx/checksums.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
tarball=sphinx-VERSION-py3-none-any.whl
2-
sha1=f9af5608fbb188f12e38d3c09cdefeef40255365
3-
sha256=c2419e2135d11f1951cd994d6eb18a1835bd8fdd8429f9ca375dc1f3281bd239
2+
sha1=67dc18611c44f712539585db41aaee4b0a7ec646
3+
sha256=09719015511837b76bf6e03e42eb7595ac8c2e41eeb9c29c5b755c6b677992a2
44
upstream_url=https://files.pythonhosted.org/packages/py3/s/sphinx/sphinx-VERSION-py3-none-any.whl

build/pkgs/sphinx/package-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.4.7
1+
8.1.3

src/sage_docbuild/ext/sage_autodoc.py

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@
3737
- François Bissey (2024-09-10): Tweaks to support python 3.9 (and older sphinx) as well
3838
3939
- François Bissey (2024-11-12): rebased on Sphinx 8.1.3 (while trying to keep python 3.9 compatibility)
40+
41+
- François Bissey (2025-02-24): Remove python 3.9 support hacks, making us closer to upstream
4042
"""
4143

4244
from __future__ import annotations
4345

4446
import functools
4547
import operator
46-
import sys
4748
import re
4849
from inspect import Parameter, Signature
4950
from typing import TYPE_CHECKING, Any, NewType, TypeVar
@@ -709,7 +710,7 @@ def add_content(self, more_content: StringList | None) -> None:
709710

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

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

10861087
@classmethod
@@ -1616,14 +1617,8 @@ def __init__(self, *args: Any) -> None:
16161617
def can_document_member(
16171618
cls: type[Documenter], member: Any, membername: str, isattr: bool, parent: Any,
16181619
) -> bool:
1619-
# support both sphinx 8 and py3.9/older sphinx
1620-
try:
1621-
result_bool = isinstance(member, type) or (
1622-
isattr and isinstance(member, NewType | TypeVar))
1623-
except Exception:
1624-
result_bool = isinstance(member, type) or (
1625-
isattr and (inspect.isNewType(member) or isinstance(member, TypeVar)))
1626-
return result_bool
1620+
return isinstance(member, type) or (
1621+
isattr and isinstance(member, NewType | TypeVar))
16271622

16281623
def import_object(self, raiseerror: bool = False) -> bool:
16291624
ret = super().import_object(raiseerror)
@@ -1696,12 +1691,7 @@ def import_object(self, raiseerror: bool = False) -> bool:
16961691
# -------------------------------------------------------------------
16971692
else:
16981693
self.doc_as_attr = True
1699-
# support both sphinx 8 and py3.9/older sphinx
1700-
try:
1701-
test_bool = isinstance(self.object, NewType | TypeVar)
1702-
except Exception:
1703-
test_bool = inspect.isNewType(self.object) or isinstance(self.object, TypeVar)
1704-
if test_bool:
1694+
if isinstance(self.object, NewType | TypeVar):
17051695
modname = getattr(self.object, '__module__', self.modname)
17061696
if modname != self.modname and self.modname.startswith(modname):
17071697
bases = self.modname[len(modname):].strip('.').split('.')
@@ -1710,12 +1700,7 @@ def import_object(self, raiseerror: bool = False) -> bool:
17101700
return ret
17111701

17121702
def _get_signature(self) -> tuple[Any | None, str | None, Signature | None]:
1713-
# support both sphinx 8 and py3.9/older sphinx
1714-
try:
1715-
test_bool = isinstance(self.object, NewType | TypeVar)
1716-
except Exception:
1717-
test_bool = inspect.isNewType(self.object) or isinstance(self.object, TypeVar)
1718-
if test_bool:
1703+
if isinstance(self.object, NewType | TypeVar):
17191704
# Suppress signature
17201705
return None, None, None
17211706

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

1903-
# support both sphinx 8 and py3.9/older sphinx
1904-
try:
1905-
test_bool = isinstance(self.object, NewType | TypeVar)
1906-
except Exception:
1907-
test_bool = inspect.isNewType(self.object) or isinstance(self.object, TypeVar)
1908-
if test_bool:
1888+
if isinstance(self.object, NewType | TypeVar):
19091889
return
19101890

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

19141894
canonical_fullname = self.get_canonical_fullname()
1915-
# support both sphinx 8 and py3.9/older sphinx
1916-
try:
1917-
newtype_test = isinstance(self.object, NewType)
1918-
except Exception:
1919-
newtype_test = inspect.isNewType(self.object)
1920-
if (not self.doc_as_attr and not newtype_test
1895+
if (not self.doc_as_attr and not isinstance(self.object, NewType)
19211896
and canonical_fullname and self.fullname != canonical_fullname):
19221897
self.add_line(' :canonical: %s' % canonical_fullname, sourcename)
19231898

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

20342009
def add_content(self, more_content: StringList | None) -> None:
2035-
# support both sphinx 8 and py3.9/older sphinx
2036-
try:
2037-
newtype_test = isinstance(self.object, NewType)
2038-
except Exception:
2039-
newtype_test = inspect.isNewType(self.object)
2040-
if newtype_test:
2010+
if isinstance(self.object, NewType):
20412011
if self.config.autodoc_typehints_format == "short":
20422012
supertype = restify(self.object.__supertype__, "smart")
20432013
else:
@@ -3006,14 +2976,9 @@ def _get_property_getter(self) -> Callable | None:
30062976

30072977
def autodoc_attrgetter(app: Sphinx, obj: Any, name: str, *defargs: Any) -> Any:
30082978
"""Alternative getattr() for types"""
3009-
try:
3010-
for typ, func in app.registry.autodoc_attrgetters.items():
3011-
if isinstance(obj, typ):
3012-
return func(obj, name, *defargs)
3013-
except AttributeError:
3014-
for typ, func in app.registry.autodoc_attrgettrs.items():
3015-
if isinstance(obj, typ):
3016-
return func(obj, name, *defargs)
2979+
for typ, func in app.registry.autodoc_attrgetters.items():
2980+
if isinstance(obj, typ):
2981+
return func(obj, name, *defargs)
30172982

30182983
return safe_getattr(obj, name, *defargs)
30192984

0 commit comments

Comments
 (0)