Skip to content

Commit 2dae2d6

Browse files
authored
Update import path for Signature (#138)
The sphinx.util.inspect.Signature api has been deprecated since sphinx 2.4 and is staged for removal in the 4.0 release. [1] This commit updates the import path to use the alternative function for it that is not deprecated. This should avoid raising a deprecation warning on each function signature that is using typehints. Fixes #133 [1] https://www.sphinx-doc.org/en/latest/extdev/deprecated.html?highlight=signature
1 parent a25fa05 commit 2dae2d6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

sphinx_autodoc_typehints.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from typing import get_type_hints, TypeVar, Any, AnyStr, Tuple
66

77
from sphinx.util import logging
8-
from sphinx.util.inspect import Signature
8+
from sphinx.util.inspect import signature as Signature
9+
from sphinx.util.inspect import stringify_signature
910

1011
logger = logging.getLogger(__name__)
1112
pydata_annotations = {'Any', 'AnyStr', 'Callable', 'ClassVar', 'Literal', 'NoReturn', 'Optional',
@@ -161,7 +162,7 @@ def process_signature(app, what: str, name: str, obj, options, signature, return
161162
signature = Signature(obj)
162163
parameters = [
163164
param.replace(annotation=inspect.Parameter.empty)
164-
for param in signature.signature.parameters.values()
165+
for param in signature.parameters.values()
165166
]
166167

167168
if '<locals>' in obj.__qualname__:
@@ -190,11 +191,11 @@ def process_signature(app, what: str, name: str, obj, options, signature, return
190191
if not isinstance(method_object, (classmethod, staticmethod)):
191192
del parameters[0]
192193

193-
signature.signature = signature.signature.replace(
194+
signature = signature.replace(
194195
parameters=parameters,
195196
return_annotation=inspect.Signature.empty)
196197

197-
return signature.format_args().replace('\\', '\\\\'), None
198+
return stringify_signature(signature).replace('\\', '\\\\'), None
198199

199200

200201
def get_all_type_hints(obj, name):

0 commit comments

Comments
 (0)