diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 515c523a..31463996 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -189,7 +189,7 @@ class Script(object): completions.append((c, scope)) else: completions = [] - debug.dbg('possible scopes', scopes) + debug.dbg('possible completion scopes: %s', scopes) for s in scopes: if s.isinstance(er.Function): names = s.get_magic_function_names() @@ -229,7 +229,7 @@ class Script(object): Base for completions/goto. Basically it returns the resolved scopes under cursor. """ - debug.dbg('start: %s in %s' % (goto_path, self._parser.user_scope)) + debug.dbg('start: %s in %s', goto_path, self._parser.user_scope) user_stmt = self._user_stmt(is_completion) if not user_stmt and len(goto_path.split('\n')) > 1: diff --git a/jedi/cache.py b/jedi/cache.py index 7b260d79..cb7dc405 100644 --- a/jedi/cache.py +++ b/jedi/cache.py @@ -257,7 +257,7 @@ class ParserPickling(object): finally: gc.enable() - debug.dbg('pickle loaded', path) + debug.dbg('pickle loaded: %s', path) parser_cache[path] = parser_cache_item return parser_cache_item.parser diff --git a/jedi/debug.py b/jedi/debug.py index 6ab6ff6b..c29f5d09 100644 --- a/jedi/debug.py +++ b/jedi/debug.py @@ -49,20 +49,20 @@ def increase_indent(func): return wrapper -def dbg(*args): +def dbg(message, *args): """ Looks at the stack, to see if a debug message should be printed. """ if debug_function and enable_notice: frm = inspect.stack()[1] mod = inspect.getmodule(frm[0]) if not (mod.__name__ in ignored_modules): i = ' ' * debug_indent - debug_function(NOTICE, i + 'dbg: ' + ', '.join(u(a) for a in args)) + debug_function(NOTICE, i + 'dbg: ' + message % args) -def warning(*args): +def warning(message, *args): if debug_function and enable_warning: i = ' ' * debug_indent - debug_function(WARNING, i + 'warning: ' + ', '.join(u(a) for a in args)) + debug_function(WARNING, i + 'warning: ' + message % args) def speed(name): diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index 66ff9390..cacf591a 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -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) diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index 8fcdebbb..7c05acd3 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -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): diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index 41c1a7dd..02f3cedc 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -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 diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index d53a5566..86b7cc70 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -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]) diff --git a/jedi/evaluate/recursion.py b/jedi/evaluate/recursion.py index 620ed93e..15423d3d 100644 --- a/jedi/evaluate/recursion.py +++ b/jedi/evaluate/recursion.py @@ -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 = [] diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index e917dd17..758fe8d7 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -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 diff --git a/jedi/evaluate/sys_path.py b/jedi/evaluate/sys_path.py index 7537a6dc..59ab1230 100644 --- a/jedi/evaluate/sys_path.py +++ b/jedi/evaluate/sys_path.py @@ -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 diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index 54706c86..88821d5d 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -269,11 +269,8 @@ class Parser(object): first_pos = self.start_pos token_type, cname = self.next() if token_type != tokenize.NAME: - debug.warning( - "class: syntax err, token is not a name@%s (%s: %s)" % ( - self.start_pos[0], tokenize.tok_name[token_type], cname - ) - ) + debug.warning("class: syntax err, token is not a name@%s (%s: %s)", + self.start_pos[0], tokenize.tok_name[token_type], cname) return None cname = pr.Name(self.module, [(cname, self.start_pos)], self.start_pos, @@ -286,7 +283,7 @@ class Parser(object): token_type, _next = self.next() if _next != ':': - debug.warning("class syntax: %s@%s" % (cname, self.start_pos[0])) + debug.warning("class syntax: %s@%s", cname, self.start_pos[0]) return None # because of 2 line class initializations @@ -446,8 +443,8 @@ class Parser(object): or self.user_scope is None and self.start_pos[0] >= self.user_position[0] ): - debug.dbg('user scope found [%s] = %s' % - (self.parserline.replace('\n', ''), repr(self._scope))) + debug.dbg('user scope found [%s] = %s', + self.parserline.replace('\n', ''), self._scope) self.user_scope = self._scope self._current = typ, tok @@ -473,8 +470,8 @@ class Parser(object): # This iterator stuff is not intentional. It grew historically. for token_type, tok in self.iterator: self.module.temp_used_names = [] - # debug.dbg('main: tok=[%s] type=[%s] indent=[%s]'\ - # % (tok, tokenize.tok_name[token_type], start_position[0])) + # debug.dbg('main: tok=[%s] type=[%s] indent=[%s]', \ + # tok, tokenize.tok_name[token_type], start_position[0]) while token_type == tokenize.DEDENT and self._scope != self.module: token_type, tok = self.next() @@ -504,8 +501,7 @@ class Parser(object): if tok == 'def': func = self._parse_function() if func is None: - debug.warning("function: syntax error@%s" % - self.start_pos[0]) + debug.warning("function: syntax error@%s", self.start_pos[0]) continue self.freshscope = True self._scope = self._scope.add_scope(func, self._decorators) @@ -549,7 +545,7 @@ class Parser(object): tok = 'import' mod = None if not mod and not relative_count or tok != "import": - debug.warning("from: syntax error@%s" % self.start_pos[0]) + debug.warning("from: syntax error@%s", self.start_pos[0]) defunct = True if tok != 'import': self._gen.push_last_back() diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index 60973ade..64a54780 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -477,7 +477,7 @@ class Function(Scope): try: n.append(p.get_name()) except IndexError: - debug.warning("multiple names in param %s" % n) + debug.warning("multiple names in param %s", n) return n def get_call_signature(self, width=72, funcname=None): @@ -1018,12 +1018,12 @@ class Statement(Simple): middle, tok = parse_stmt_or_arr(token_iterator, ['in'], True) if tok != 'in' or middle is None: - debug.warning('list comprehension middle @%s' % str(start_pos)) + debug.warning('list comprehension middle @%s', start_pos) return None, tok in_clause, tok = parse_stmt_or_arr(token_iterator) if in_clause is None: - debug.warning('list comprehension in @%s' % str(start_pos)) + debug.warning('list comprehension in @%s', start_pos) return None, tok return ListComprehension(st, middle, in_clause, self), tok @@ -1156,7 +1156,7 @@ class Param(Statement): """ get the name of the param """ n = self.get_set_vars() if len(n) > 1: - debug.warning("Multiple param names (%s)." % n) + debug.warning("Multiple param names (%s).", n) return n[0] diff --git a/jedi/parser/user_context.py b/jedi/parser/user_context.py index 6736ae28..31414606 100644 --- a/jedi/parser/user_context.py +++ b/jedi/parser/user_context.py @@ -99,7 +99,7 @@ class UserContext(object): string += tok last_type = token_type except tokenize.TokenError: - debug.warning("Tokenize couldn't finish", sys.exc_info) + debug.warning("Tokenize couldn't finish: %s", sys.exc_info) # string can still contain spaces at the end return string[::-1].strip(), start_cursor