Skip to content

Commit

Permalink
Removed compatibility hack for inspect.unwrap
Browse files Browse the repository at this point in the history
We require Python 3.5+ now so this is no longer needed.
  • Loading branch information
agronholm committed Jul 23, 2019
1 parent d4b7858 commit 0d3b755
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions sphinx_autodoc_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@
except ImportError:
Protocol = None

try:
from inspect import unwrap
except ImportError:
def unwrap(func, *, stop=None):
"""This is the inspect.unwrap() method copied from Python 3.5's standard library."""
if stop is None:
def _is_wrapper(f):
return hasattr(f, '__wrapped__')
else:
def _is_wrapper(f):
return hasattr(f, '__wrapped__') and not stop(f)
f = func # remember the original func for error reporting
memo = {id(f)} # Memoise by id to tolerate non-hashable objects
while _is_wrapper(func):
func = func.__wrapped__
id_func = id(func)
if id_func in memo:
raise ValueError('wrapper loop when unwrapping {!r}'.format(f))
memo.add(id_func)
return func

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -167,7 +146,7 @@ def process_signature(app, what: str, name: str, obj, options, signature, return
if not getattr(obj, '__annotations__', None):
return

obj = unwrap(obj)
obj = inspect.unwrap(obj)
signature = Signature(obj)
parameters = [
param.replace(annotation=inspect.Parameter.empty)
Expand Down Expand Up @@ -320,7 +299,7 @@ def process_docstring(app, what, name, obj, options, lines):
if what in ('class', 'exception'):
obj = getattr(obj, '__init__')

obj = unwrap(obj)
obj = inspect.unwrap(obj)
type_hints = get_all_type_hints(obj, name)

for argname, annotation in type_hints.items():
Expand Down

0 comments on commit 0d3b755

Please sign in to comment.