Skip to content

Commit

Permalink
Hints: Make import tracer robust against imports from "print" function.
Browse files Browse the repository at this point in the history
* Also be more Python3 compatible by using proper level default for that
  version.
  • Loading branch information
kayhayen committed Mar 16, 2018
1 parent 998de9e commit 05c27e0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def _moduleRepr(module):
def enableImportTracing(normalize_paths = True, show_source = False):

def _ourimport(name, globals = None, locals = None, fromlist = None, # @ReservedAssignment
level = -1):
level = -1 if sys.version_info[0] < 2 else 0):
builtins.__import__ = original_import

global _indentation
try:
_indentation += 1
Expand All @@ -85,8 +87,13 @@ def _ourimport(name, globals = None, locals = None, fromlist = None, # @Reserve

print(_indentation * " " + "*" * 40)

builtins.__import__ = _ourimport
result = original_import(name, globals, locals, fromlist, level)
builtins.__import__ = original_import
print(_indentation * " " + "RESULT:", _moduleRepr(result))
print(_indentation * " " + "*" * 40)
builtins.__import__ = _ourimport

return result
finally:
_indentation -= 1
Expand Down

0 comments on commit 05c27e0

Please sign in to comment.