Skip to content

Commit cf79a05

Browse files
committed
remove py3.9 and older sphinx work arounds introduced in the last two synchronization of sage_autodoc.py with upstream
1 parent 9cd86e9 commit cf79a05

File tree

1 file changed

+14
-49
lines changed

1 file changed

+14
-49
lines changed

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)