Skip to content

Commit

Permalink
Add annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jul 24, 2022
1 parent 38219c8 commit fc9b7af
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sphinx/ext/autodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,11 @@ def format_args(self, **kwargs: Any) -> str:
if self.config.autodoc_typehints_format == "short":
kwargs.setdefault('unqualified_typehints', True)

__annotations__ = getattr(self.object, "__annotations__", {})
try:
if inspect.isNewType(self.object):
self.object.__annotations__["x"] = self.object.__supertype__
self.object.__annotations__["return"] = self.object
self.env.app.emit('autodoc-before-process-signature', self.object, False)
sig = inspect.signature(self.object, type_aliases=self.config.autodoc_type_aliases)
args = stringify_signature(sig, **kwargs)
Expand All @@ -1279,6 +1283,8 @@ def format_args(self, **kwargs: Any) -> str:
return None
except ValueError:
args = ''
finally:
self.object.__annotations__ = __annotations__

if self.config.strip_signature_backslash:
# escape backslashes for reST
Expand Down Expand Up @@ -1483,13 +1489,19 @@ def get_user_defined_function_or_method(obj: Any, attr: str) -> Any:
call = None

if call is not None:
__annotations__ = getattr(self.object, "__annotations__", {})
if inspect.isNewType(self.object):
call.__annotations__["x"] = self.object.__supertype__
call.__annotations__["return"] = self.object
self.env.app.emit('autodoc-before-process-signature', call, True)
try:
sig = inspect.signature(call, bound_method=True,
type_aliases=self.config.autodoc_type_aliases)
return type(self.object), '__call__', sig
except ValueError:
pass
finally:
self.object.__annotations__ = __annotations__

# Now we check if the 'obj' class has a '__new__' method
new = get_user_defined_function_or_method(self.object, '__new__')
Expand Down

0 comments on commit fc9b7af

Please sign in to comment.