Skip to content

Commit

Permalink
use our unwrapper because inspect.unwrap not exist in python2
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricporter committed Feb 24, 2017
1 parent f40e0df commit dd8f6c4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rqalpha/api/api_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from ..model.instrument import SectorCodeItem, IndustryCodeItem
from ..execution_context import ExecutionContext
from ..const import EXECUTION_PHASE, EXC_TYPE, ORDER_STATUS, SIDE, POSITION_EFFECT, ORDER_TYPE, MATCHING_TYPE, RUN_TYPE
from ..utils import to_industry_code, to_sector_name
from ..utils import to_industry_code, to_sector_name, unwrapper
from ..utils.exception import patch_user_exc, patch_system_exc, EXC_EXT_NAME
from ..utils.i18n import gettext as _
from ..model.snapshot import SnapshotObject
Expand Down Expand Up @@ -87,7 +87,7 @@ def deco(*args, **kwargs):
if isinstance(e, TypeError):
exc_info = sys.exc_info()
try:
ret = inspect.getcallargs(inspect.unwrap(func), *args, **kwargs)
ret = inspect.getcallargs(unwrapper(func), *args, **kwargs)
except TypeError:
t, v, tb = exc_info
raise patch_user_exc(v.with_traceback(tb))
Expand Down
10 changes: 10 additions & 0 deletions rqalpha/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,13 @@ def run_with_user_log_disabled(disabled=True):
finally:
if disabled:
user_log.enable()


def unwrapper(func):
f2 = func
while True:
f = f2
f2 = getattr(f2, "__wrapped__", None)
if f2 is None:
break
return f
4 changes: 2 additions & 2 deletions rqalpha/utils/arg_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from ..model.instrument import Instrument
from ..environment import Environment
from ..const import INSTRUMENT_TYPE, RUN_TYPE
from ..utils import INST_TYPE_IN_STOCK_ACCOUNT
from ..utils import unwrapper, INST_TYPE_IN_STOCK_ACCOUNT
from ..utils.i18n import gettext as _
from ..utils.logger import user_system_log

Expand Down Expand Up @@ -353,7 +353,7 @@ def api_rule_check_wrapper(*args, **kwargs):
t, v, tb = exc_info

try:
call_args = inspect.getcallargs(inspect.unwrap(func), *args, **kwargs)
call_args = inspect.getcallargs(unwrapper(func), *args, **kwargs)
except TypeError as e:
raise RQTypeError(*e.args).with_traceback(tb)

Expand Down

0 comments on commit dd8f6c4

Please sign in to comment.