Skip to content

Commit

Permalink
Merge pull request tornadoweb#1776 from SuminAndrew/exec_in-rewrite
Browse files Browse the repository at this point in the history
simplify tornado.util.exec_in
  • Loading branch information
bdarnell authored Jul 25, 2016
2 parents e223ca5 + c8c9a08 commit ead8497
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions tornado/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<string>', '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, '<string>', '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, '<string>', 'exec', dont_inherit=True)
exec code in glob, loc
""")


Expand Down

0 comments on commit ead8497

Please sign in to comment.