fixes #2208 by introducing a iteration limit

This commit is contained in:
Ronny Pfannschmidt
2017-01-19 11:38:15 +01:00
parent 6c011f43e9
commit 123289a88e
3 changed files with 44 additions and 6 deletions

View File

@@ -180,8 +180,16 @@ def get_real_func(obj):
""" gets the real function object of the (possibly) wrapped object by
functools.wraps or functools.partial.
"""
while hasattr(obj, "__wrapped__"):
obj = obj.__wrapped__
start_obj = obj
for i in range(100):
new_obj = getattr(obj, '__wrapped__', None)
if new_obj is None:
break
obj = new_obj
else:
raise ValueError(
("could not find real function of {start}"
"\nstopped at {current}").format(start=start_obj, current=obj))
if isinstance(obj, functools.partial):
obj = obj.func
return obj