@@ -599,6 +599,11 @@ def test_mocked_module_imports(app, warning):
599599@pytest .mark .sphinx ('html' , testroot = 'ext-autodoc' ,
600600 confoverrides = {'autodoc_typehints' : "signature" })
601601def test_autodoc_typehints_signature (app ):
602+ if sys .version_info < (3 , 11 ):
603+ type_o = "typing.Optional[typing.Any]"
604+ else :
605+ type_o = "typing.Any"
606+
602607 options = {"members" : None ,
603608 "undoc-members" : None }
604609 actual = do_autodoc (app , 'module' , 'target.typehints' , options )
@@ -612,7 +617,7 @@ def test_autodoc_typehints_signature(app):
612617 ' :type: int' ,
613618 '' ,
614619 '' ,
615- '.. py:class:: Math(s: str, o: typing.Optional[typing.Any] = None)' ,
620+ '.. py:class:: Math(s: str, o: %s = None)' % type_o ,
616621 ' :module: target.typehints' ,
617622 '' ,
618623 '' ,
@@ -1146,6 +1151,11 @@ def test_autodoc_typehints_description_and_type_aliases(app):
11461151@pytest .mark .sphinx ('html' , testroot = 'ext-autodoc' ,
11471152 confoverrides = {'autodoc_typehints_format' : "short" })
11481153def test_autodoc_typehints_format_short (app ):
1154+ if sys .version_info < (3 , 11 ):
1155+ type_o = "~typing.Optional[~typing.Any]"
1156+ else :
1157+ type_o = "~typing.Any"
1158+
11491159 options = {"members" : None ,
11501160 "undoc-members" : None }
11511161 actual = do_autodoc (app , 'module' , 'target.typehints' , options )
@@ -1159,7 +1169,7 @@ def test_autodoc_typehints_format_short(app):
11591169 ' :type: int' ,
11601170 '' ,
11611171 '' ,
1162- '.. py:class:: Math(s: str, o: ~typing.Optional[~typing.Any] = None)' ,
1172+ '.. py:class:: Math(s: str, o: %s = None)' % type_o ,
11631173 ' :module: target.typehints' ,
11641174 '' ,
11651175 '' ,
0 commit comments