37
37
- François Bissey (2024-09-10): Tweaks to support python 3.9 (and older sphinx) as well
38
38
39
39
- 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
40
42
"""
41
43
42
44
from __future__ import annotations
43
45
44
46
import functools
45
47
import operator
46
- import sys
47
48
import re
48
49
from inspect import Parameter , Signature
49
50
from typing import TYPE_CHECKING , Any , NewType , TypeVar
@@ -709,7 +710,7 @@ def add_content(self, more_content: StringList | None) -> None:
709
710
710
711
# add additional content (e.g. from document), if present
711
712
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 ):
713
714
self .add_line (line , src [0 ], src [1 ])
714
715
715
716
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:
1080
1081
super ().add_content (None )
1081
1082
self .indent = old_indent
1082
1083
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 ):
1084
1085
self .add_line (line , src [0 ], src [1 ])
1085
1086
1086
1087
@classmethod
@@ -1616,14 +1617,8 @@ def __init__(self, *args: Any) -> None:
1616
1617
def can_document_member (
1617
1618
cls : type [Documenter ], member : Any , membername : str , isattr : bool , parent : Any ,
1618
1619
) -> 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 ))
1627
1622
1628
1623
def import_object (self , raiseerror : bool = False ) -> bool :
1629
1624
ret = super ().import_object (raiseerror )
@@ -1696,12 +1691,7 @@ def import_object(self, raiseerror: bool = False) -> bool:
1696
1691
# -------------------------------------------------------------------
1697
1692
else :
1698
1693
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 ):
1705
1695
modname = getattr (self .object , '__module__' , self .modname )
1706
1696
if modname != self .modname and self .modname .startswith (modname ):
1707
1697
bases = self .modname [len (modname ):].strip ('.' ).split ('.' )
@@ -1710,12 +1700,7 @@ def import_object(self, raiseerror: bool = False) -> bool:
1710
1700
return ret
1711
1701
1712
1702
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 ):
1719
1704
# Suppress signature
1720
1705
return None , None , None
1721
1706
@@ -1900,24 +1885,14 @@ def add_directive_header(self, sig: str) -> None:
1900
1885
self .directivetype = 'attribute'
1901
1886
super ().add_directive_header (sig )
1902
1887
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 ):
1909
1889
return
1910
1890
1911
1891
if self .analyzer and '.' .join (self .objpath ) in self .analyzer .finals :
1912
1892
self .add_line (' :final:' , sourcename )
1913
1893
1914
1894
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 )
1921
1896
and canonical_fullname and self .fullname != canonical_fullname ):
1922
1897
self .add_line (' :canonical: %s' % canonical_fullname , sourcename )
1923
1898
@@ -2032,12 +2007,7 @@ def get_variable_comment(self) -> list[str] | None:
2032
2007
return None
2033
2008
2034
2009
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 ):
2041
2011
if self .config .autodoc_typehints_format == "short" :
2042
2012
supertype = restify (self .object .__supertype__ , "smart" )
2043
2013
else :
@@ -3006,14 +2976,9 @@ def _get_property_getter(self) -> Callable | None:
3006
2976
3007
2977
def autodoc_attrgetter (app : Sphinx , obj : Any , name : str , * defargs : Any ) -> Any :
3008
2978
"""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 )
3017
2982
3018
2983
return safe_getattr (obj , name , * defargs )
3019
2984
0 commit comments