mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
Merge pull request #191 from dequis/signature-preserving-decorator
Make hooks.wrap preserve signatures, fixes hooking some pyqt5 callbacks
This commit is contained in:
commit
896889ad82
2 changed files with 17 additions and 1 deletions
|
@ -13,6 +13,14 @@ If you call wrap() with pos='around', the original function will not be called
|
||||||
automatically but can be called with _old().
|
automatically but can be called with _old().
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import functools
|
||||||
|
|
||||||
|
try:
|
||||||
|
# optional: like functools.wraps, but signature-preserving
|
||||||
|
import decorator
|
||||||
|
except ImportError:
|
||||||
|
decorator = None
|
||||||
|
|
||||||
# Hooks
|
# Hooks
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
@ -59,4 +67,11 @@ def wrap(old, new, pos="after"):
|
||||||
return old(*args, **kwargs)
|
return old(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
return new(_old=old, *args, **kwargs)
|
return new(_old=old, *args, **kwargs)
|
||||||
return repl
|
|
||||||
|
if decorator is None:
|
||||||
|
return functools.wraps(repl)
|
||||||
|
|
||||||
|
def decorator_wrapper(f, *args, **kwargs):
|
||||||
|
return repl(*args, **kwargs)
|
||||||
|
|
||||||
|
return decorator.decorator(decorator_wrapper)(old)
|
||||||
|
|
|
@ -3,3 +3,4 @@ send2trash
|
||||||
httplib2
|
httplib2
|
||||||
pyaudio
|
pyaudio
|
||||||
requests
|
requests
|
||||||
|
decorator
|
||||||
|
|
Loading…
Reference in a new issue