1
0
forked from VimPlug/jedi

debug.dbg and debug.warning now take a string and format args parameters to make debugging a little bit cleaner

This commit is contained in:
Dave Halter
2014-01-13 16:16:07 +01:00
parent 157f76a55d
commit 682e1c2708
13 changed files with 58 additions and 65 deletions
+10 -10
View File
@@ -205,7 +205,7 @@ class Evaluator(object):
:param stmt: A `pr.Statement`.
"""
debug.dbg('eval_statement %s (%s)' % (stmt, seek_name))
debug.dbg('eval_statement %s (%s)', stmt, seek_name)
expression_list = stmt.expression_list()
result = self.eval_expression_list(expression_list)
@@ -242,7 +242,7 @@ class Evaluator(object):
loop = evaluate_list_comprehension(nested_lc, loop)
return loop
debug.dbg('eval_expression_list: %s' % expression_list)
debug.dbg('eval_expression_list: %s', expression_list)
result = []
calls_iterator = iter(expression_list)
for call in calls_iterator:
@@ -354,7 +354,7 @@ class Evaluator(object):
current = next(path)
except StopIteration:
return None
debug.dbg('_follow_path: %s in scope %s' % (current, typ))
debug.dbg('_follow_path: %s in scope %s', current, typ)
result = []
if isinstance(current, pr.Array):
@@ -367,7 +367,7 @@ class Evaluator(object):
result = self.execute(typ, current)
else:
# Curly braces are not allowed, because they make no sense.
debug.warning('strange function call with {}', current, typ)
debug.warning('strange function call with {} %s %s', current, typ)
else:
# The function must not be decorated with something else.
if typ.isinstance(er.Function):
@@ -385,7 +385,7 @@ class Evaluator(object):
if obj.isinstance(er.Function):
obj = obj.get_decorated_func()
debug.dbg('execute:', obj, params)
debug.dbg('execute: %s %s', obj, params)
try:
return stdlib.execute(self, obj, params)
except stdlib.NotInStdLib:
@@ -410,11 +410,11 @@ class Evaluator(object):
try:
stmts = obj.execute_subscope_by_name('__call__', params)
except KeyError:
debug.warning("no __call__ func available", obj)
debug.warning("no __call__ func available %s", obj)
else:
debug.warning("no execution possible", obj)
debug.warning("no execution possible %s", obj)
debug.dbg('execute result: %s in %s' % (stmts, obj))
debug.dbg('execute result: %s in %s', stmts, obj)
return imports.strip_imports(self, stmts)
def goto(self, stmt, call_path=None):
@@ -482,8 +482,8 @@ def _assign_tuples(tup, results, seek_name):
try:
func = r.get_exact_index_types
except AttributeError:
debug.warning("invalid tuple lookup %s of result %s in %s"
% (tup, results, seek_name))
debug.warning("invalid tuple lookup %s of result %s in %s",
tup, results, seek_name)
else:
with common.ignored(IndexError):
types += func(index)
+3 -3
View File
@@ -22,7 +22,7 @@ class NameFinder(object):
def find(self, scopes, resolve_decorator=True):
names = self.filter_name(scopes)
types = self._names_to_types(names, resolve_decorator)
debug.dbg('_names_to_types: %s, old: %s' % (names, types))
debug.dbg('_names_to_types: %s, old: %s', names, types)
return self._resolve_descriptors(types)
def scopes(self, search_global=False):
@@ -76,8 +76,8 @@ class NameFinder(object):
new_name.parent = r
result.append(new_name)
debug.dbg('sfn filter "%s" in (%s-%s): %s@%s'
% (self.name_str, self.scope, nscope, u(result), self.position))
debug.dbg('sfn filter "%s" in (%s-%s): %s@%s', self.name_str,
self.scope, nscope, u(result), self.position)
return result
def _check_getattr(self, inst):
+5 -5
View File
@@ -94,7 +94,7 @@ class ImportPath(pr.Base):
n = pr.Name(i._sub_module, names, zero, zero, self.import_stmt)
new = pr.Import(i._sub_module, zero, zero, n)
new.parent = parent
debug.dbg('Generated a nested import: %s' % new)
debug.dbg('Generated a nested import: %s', new)
return new
def get_defined_names(self, on_import_stmt=False):
@@ -193,7 +193,7 @@ class ImportPath(pr.Base):
try:
scope, rest = self._follow_file_system()
except ModuleNotFound:
debug.warning('Module not found: ' + str(self.import_stmt))
debug.warning('Module not found: %s', self.import_stmt)
self._evaluator.recursion_detector.pop_stmt()
return []
@@ -225,7 +225,7 @@ class ImportPath(pr.Base):
scopes.append(self._get_nested_import(scope))
else:
scopes = [ImportPath.GlobalNamespace]
debug.dbg('after import', scopes)
debug.dbg('after import: %s', scopes)
self._evaluator.recursion_detector.pop_stmt()
return scopes
@@ -295,7 +295,7 @@ class ImportPath(pr.Base):
Find a module with a path (of the module, like usb.backend.libusb10).
"""
def follow_str(ns_path, string):
debug.dbg('follow_module', ns_path, string)
debug.dbg('follow_module %s %s', ns_path, string)
path = None
if ns_path:
path = ns_path
@@ -305,7 +305,7 @@ class ImportPath(pr.Base):
if path is not None:
importing = find_module(string, [path])
else:
debug.dbg('search_module', string, self.file_path)
debug.dbg('search_module %s %s', string, self.file_path)
# Override the sys.path. It works only good that way.
# Injecting the path directly into `find_module` did not work.
sys.path, temp = sys_path, sys.path
+5 -7
View File
@@ -28,7 +28,7 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base)):
for n in ('close', 'throw') + executes_generator:
parent = self if n in executes_generator else compiled.builtin
names.append(helpers.FakeName(n, parent))
debug.dbg('generator names', names)
debug.dbg('generator names: %s', names)
return names
def iter_content(self):
@@ -36,7 +36,7 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base)):
return self._evaluator.execute(self.func, self.var_args, True)
def get_index_types(self, index=None):
debug.warning('Tried to get array access on a generator', self)
debug.warning('Tried to get array access on a generator: %s', self)
return []
def __getattr__(self, name):
@@ -183,7 +183,7 @@ def get_iterator_types(inputs):
iterators.append(it)
else:
if not hasattr(it, 'execute_subscope_by_name'):
debug.warning('iterator/for loop input wrong', it)
debug.warning('iterator/for loop input wrong: %s', it)
continue
try:
iterators += it.execute_subscope_by_name('__iter__')
@@ -204,7 +204,7 @@ def get_iterator_types(inputs):
try:
result += gen.execute_subscope_by_name(name)
except KeyError:
debug.warning('Instance has no __next__ function', gen)
debug.warning('Instance has no __next__ function in %s.', gen)
else:
# is a generator
result += gen.iter_content()
@@ -363,9 +363,7 @@ class ArrayInstance(pr.Base):
if self.var_args.start_pos != array.var_args.start_pos:
items += array.iter_content()
else:
debug.warning(
'ArrayInstance recursion',
self.var_args)
debug.warning('ArrayInstance recursion %s', self.var_args)
continue
items += get_iterator_types([typ])
+3 -3
View File
@@ -40,8 +40,8 @@ class RecursionDetector(object):
self.current = _RecursionNode(stmt, self.current)
check = self._check_recursion()
if check: # TODO remove False!!!!
debug.warning('catched stmt recursion: %s against %s @%s'
% (stmt, check.stmt, stmt.start_pos))
debug.warning('catched stmt recursion: %s against %s @%s', stmt,
check.stmt, stmt.start_pos)
self.pop_stmt()
return True
return False
@@ -121,7 +121,7 @@ class ExecutionRecursionDetector(object):
self.execution_count = 0
def __call__(self, execution, evaluate_generator=False):
debug.dbg('Execution recursions: %s' % execution, self.recursion_level,
debug.dbg('Execution recursions: %s', execution, self.recursion_level,
self.execution_count, len(self.execution_funcs))
if self.check_recursion(execution, evaluate_generator):
result = []
+8 -9
View File
@@ -334,16 +334,15 @@ class Function(use_metaclass(CachedMetaClass, pr.IsScope)):
# Only enter it, if has not already been processed.
if not self.is_decorated:
for dec in reversed(self.base_func.decorators):
debug.dbg('decorator:', dec, f)
debug.dbg('decorator: %s %s', dec, f)
dec_results = set(self._evaluator.eval_statement(dec))
if not len(dec_results):
debug.warning('decorator not found: %s on %s' %
(dec, self.base_func))
debug.warning('decorator not found: %s on %s', dec, self.base_func)
return None
decorator = dec_results.pop()
if dec_results:
debug.warning('multiple decorators found', self.base_func,
dec_results)
debug.warning('multiple decorators found %s %s',
self.base_func, dec_results)
# Create param array.
old_func = Function(self._evaluator, f, is_decorated=True)
if instance is not None and decorator.isinstance(Function):
@@ -352,15 +351,15 @@ class Function(use_metaclass(CachedMetaClass, pr.IsScope)):
wrappers = self._evaluator.execute(decorator, (old_func,))
if not len(wrappers):
debug.warning('no wrappers found', self.base_func)
debug.warning('no wrappers found %s', self.base_func)
return None
if len(wrappers) > 1:
# TODO resolve issue with multiple wrappers -> multiple types
debug.warning('multiple wrappers found', self.base_func,
wrappers)
debug.warning('multiple wrappers found %s %s',
self.base_func, wrappers)
f = wrappers[0]
debug.dbg('decorator end', f)
debug.dbg('decorator end %s', f)
if f != self.base_func and isinstance(f, pr.Function):
f = Function(self._evaluator, f)
return f
+3 -3
View File
@@ -75,14 +75,14 @@ def sys_path_with_modifications(module):
res = execute_code(exe.get_code())
if res is not None:
sys_path.insert(0, res)
debug.dbg('sys path inserted: %s' % res)
debug.dbg('sys path inserted: %s', res)
exe.type = exe_type
exe.values.insert(0, exe_pop)
elif array_cmd == 'append':
res = execute_code(exe.get_code())
if res is not None:
sys_path.append(res)
debug.dbg('sys path added: %s' % res)
debug.dbg('sys path added: %s', res)
return sys_path
if module.path is None:
@@ -115,6 +115,6 @@ def _detect_django_path(module_path):
with common.ignored(IOError):
with open(module_path + os.path.sep + 'manage.py'):
debug.dbg('Found django path: %s' % module_path)
debug.dbg('Found django path: %s', module_path)
result.append(module_path)
return result