From: Andrey Sumin Date: Thu, 21 Jul 2016 13:11:06 +0000 (+0300) Subject: simplify tornado.util.exec_in X-Git-Tag: v4.5.0~88^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1776%2Fhead;p=thirdparty%2Ftornado.git simplify tornado.util.exec_in --- 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 """)