From c8c9a08c2304d5ae8c3951c5982b2ec624adf073 Mon Sep 17 00:00:00 2001 From: Andrey Sumin Date: Thu, 21 Jul 2016 16:11:06 +0300 Subject: [PATCH] simplify tornado.util.exec_in --- tornado/util.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/tornado/util.py b/tornado/util.py index 53584f98b..28e74e7dc 100644 --- a/tornado/util.py +++ b/tornado/util.py @@ -165,30 +165,22 @@ def raise_exc_info(exc_info): def exec_in(code, glob, loc=None): # type: (Any, Dict[str, Any], Optional[Mapping[str, Any]]) -> Any - pass + if isinstance(code, basestring_type): + # exec(string) inherits the caller's future imports; compile + # the string first to prevent that. + code = compile(code, '', 'exec', dont_inherit=True) + exec(code, glob, loc) if PY3: exec(""" def raise_exc_info(exc_info): raise exc_info[1].with_traceback(exc_info[2]) - -def exec_in(code, glob, loc=None): - if isinstance(code, str): - code = compile(code, '', 'exec', dont_inherit=True) - exec(code, glob, loc) """) else: exec(""" def raise_exc_info(exc_info): raise exc_info[0], exc_info[1], exc_info[2] - -def exec_in(code, glob, loc=None): - if isinstance(code, basestring): - # exec(string) inherits the caller's future imports; compile - # the string first to prevent that. - code = compile(code, '', 'exec', dont_inherit=True) - exec code in glob, loc """) -- 2.47.2