From 0d6e2a5b707933327430568dd056f1f20100a796 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Sat, 20 Oct 2012 23:39:48 +0200 Subject: [PATCH 1/3] Replaced `type()` comparison with cleaner `isinstance` --- jedi/keywords.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jedi/keywords.py b/jedi/keywords.py index 1e595c68..334db13a 100644 --- a/jedi/keywords.py +++ b/jedi/keywords.py @@ -68,7 +68,7 @@ def imitate_pydoc(string): pass get_target = lambda s: h.topics.get(s, h.keywords.get(s)) - while type(string) == type(''): + while isinstance(string, str): string = get_target(string) try: From 55aeeb00b7f03e8d8d2410d455f51c20c8f089de Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Sat, 20 Oct 2012 23:42:39 +0200 Subject: [PATCH 2/3] Don't assign to `str` --- jedi/parsing.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/jedi/parsing.py b/jedi/parsing.py index 0c1b9797..a2107a1d 100644 --- a/jedi/parsing.py +++ b/jedi/parsing.py @@ -326,16 +326,16 @@ class Class(Scope): self.decorators = [] def get_code(self, first_indent=False, indention=" "): - str = "\n".join('@' + stmt.get_code() for stmt in self.decorators) - str += 'class %s' % (self.name) + string = "\n".join('@' + stmt.get_code() for stmt in self.decorators) + string += 'class %s' % (self.name) if len(self.supers) > 0: sup = ','.join(stmt.code for stmt in self.supers) - str += '(%s)' % sup - str += ':\n' - str += super(Class, self).get_code(True, indention) + string += '(%s)' % sup + string += ':\n' + string += super(Class, self).get_code(True, indention) if self.is_empty(): - str += "pass\n" - return str + string += "pass\n" + return string class Function(Scope): @@ -368,13 +368,13 @@ class Function(Scope): self.annotation = annotation def get_code(self, first_indent=False, indention=" "): - str = "\n".join('@' + stmt.get_code() for stmt in self.decorators) + string = "\n".join('@' + stmt.get_code() for stmt in self.decorators) params = ','.join([stmt.code for stmt in self.params]) - str += "def %s(%s):\n" % (self.name, params) - str += super(Function, self).get_code(True, indention) + string += "def %s(%s):\n" % (self.name, params) + string += super(Function, self).get_code(True, indention) if self.is_empty(): - str += "pass\n" - return str + string += "pass\n" + return string def get_set_vars(self): n = super(Function, self).get_set_vars() @@ -441,11 +441,11 @@ class Flow(Scope): for s in self.inits: stmts.append(s.get_code(new_line=False)) stmt = ', '.join(stmts) - str = "%s %s:\n" % (self.command, vars, stmt) - str += super(Flow, self).get_code(True, indention) + string = "%s %s:\n" % (self.command, vars, stmt) + string += super(Flow, self).get_code(True, indention) if self.next: - str += self.next.get_code() - return str + string += self.next.get_code() + return string def get_set_vars(self, is_internal_call=False): """ From c5b9eca9d1f88aaf07ad41ac4ec4a068382ac740 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Sat, 20 Oct 2012 23:43:13 +0200 Subject: [PATCH 3/3] Trivial refactorings --- jedi/dynamic.py | 2 +- jedi/modules.py | 2 +- jedi/parsing.py | 44 ++++++++++++++++++++++---------------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/jedi/dynamic.py b/jedi/dynamic.py index fdc4a136..abd26485 100644 --- a/jedi/dynamic.py +++ b/jedi/dynamic.py @@ -542,7 +542,7 @@ def check_statement_information(stmt, search_name): classes_call = isinst[1][0] # class_or_type_or_tuple assert isinstance(classes_call, parsing.Call) result = [] - for c in evaluate.follow_call(classes_call): + for c in evaluate.follow_call(classes_call): if isinstance(c, evaluate.Array): result += c.get_index_types() else: diff --git a/jedi/modules.py b/jedi/modules.py index 887248b4..d4f91cb2 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -227,7 +227,7 @@ def sys_path_with_modifications(module): if call.execution is None: continue exe = call.execution - if not (array_cmd == 'insert' and len(exe) == 2 \ + if not (array_cmd == 'insert' and len(exe) == 2 or array_cmd == 'append' and len(exe) == 1): continue diff --git a/jedi/parsing.py b/jedi/parsing.py index a2107a1d..fc180ae9 100644 --- a/jedi/parsing.py +++ b/jedi/parsing.py @@ -44,7 +44,7 @@ class ParserError(Exception): pass -def indent_block(text, indention=" "): +def indent_block(text, indention=' '): """ This function indents a text block with a default of four spaces """ temp = '' while text and text[-1] == '\n': @@ -176,7 +176,7 @@ class Scope(Simple): i += s.get_imports() return i - def get_code(self, first_indent=False, indention=" "): + def get_code(self, first_indent=False, indention=' '): """ :return: Returns the code of the current scope. :rtype: str @@ -220,8 +220,8 @@ class Scope(Simple): return n def get_defined_names(self): - return [n for n in self.get_set_vars() \ - if isinstance(n, Import) or len(n) == 1] + return [n for n in self.get_set_vars() + if isinstance(n, Import) or len(n) == 1] def is_empty(self): """ @@ -325,7 +325,7 @@ class Class(Scope): s.parent = weakref.ref(self) self.decorators = [] - def get_code(self, first_indent=False, indention=" "): + def get_code(self, first_indent=False, indention=' '): string = "\n".join('@' + stmt.get_code() for stmt in self.decorators) string += 'class %s' % (self.name) if len(self.supers) > 0: @@ -367,7 +367,7 @@ class Function(Scope): annotation.parent = weakref.ref(self) self.annotation = annotation - def get_code(self, first_indent=False, indention=" "): + def get_code(self, first_indent=False, indention=' '): string = "\n".join('@' + stmt.get_code() for stmt in self.decorators) params = ','.join([stmt.code for stmt in self.params]) string += "def %s(%s):\n" % (self.name, params) @@ -418,7 +418,7 @@ class Flow(Scope): self.inits = inits for s in inits: s.parent = weakref.ref(self) - if set_vars == None: + if set_vars is None: self.set_vars = [] else: self.set_vars = set_vars @@ -436,7 +436,7 @@ class Flow(Scope): if self.next: self.next.parent = value - def get_code(self, first_indent=False, indention=" "): + def get_code(self, first_indent=False, indention=' '): stmts = [] for s in self.inits: stmts.append(s.get_code(new_line=False)) @@ -522,8 +522,8 @@ class Import(Simple): :param defunct: An Import is valid or not. :type defunct: bool """ - def __init__(self, start_pos, end_pos, namespace, alias=None, \ - from_ns=None, star=False, relative_count=0, defunct=False): + def __init__(self, start_pos, end_pos, namespace, alias=None, + from_ns=None, star=False, relative_count=0, defunct=False): super(Import, self).__init__(start_pos, end_pos) self.namespace = namespace @@ -807,7 +807,7 @@ class Statement(Simple): if level != 0: debug.warning("Brackets don't match: %s." - "This is not normal behaviour." % level) + "This is not normal behaviour." % level) self._assignment_calls_calculated = True self._assignment_calls = top @@ -819,10 +819,10 @@ class Param(Statement): The class which shows definitions of params of classes and functions. But this is not to define function calls. """ - def __init__(self, code, set_vars, used_funcs, used_vars, token_list, - start_pos, end_pos): - super(Param, self).__init__(code, set_vars, used_funcs, - used_vars, token_list, start_pos, end_pos) + def __init__(self, code, set_vars, used_funcs, used_vars, + token_list, start_pos, end_pos): + super(Param, self).__init__(code, set_vars, used_funcs, used_vars, + token_list, start_pos, end_pos) # this is defined by the parser later on, not at the initialization # it is the position in the call (first argument, second...) @@ -1024,10 +1024,10 @@ class Array(Call): return str(el) map = {Array.NOARRAY: '%s', - Array.TUPLE: '(%s)', - Array.LIST: '[%s]', - Array.DICT: '{%s}', - Array.SET: '{%s}' + Array.TUPLE: '(%s)', + Array.LIST: '[%s]', + Array.DICT: '{%s}', + Array.SET: '{%s}' } inner = [] for i, value in enumerate(self.values): @@ -1077,7 +1077,7 @@ class Name(Simple): def __init__(self, names, start_pos, end_pos, parent=None): super(Name, self).__init__(start_pos, end_pos) self.names = tuple(n if isinstance(n, NamePart) else NamePart(*n) - for n in names) + for n in names) if parent is not None: self.parent = weakref.ref(parent) @@ -1484,7 +1484,7 @@ class PyFuzzyParser(object): for t in toks: src += t[1] if isinstance(t, tuple) \ else t.get_code() - st = Statement(src, [], [], [], \ + st = Statement(src, [], [], [], toks, first_pos, self.end_pos) for s in [st, middle, in_clause]: @@ -1534,7 +1534,7 @@ class PyFuzzyParser(object): self.scope.add_docstr(self.last_token[1]) return None, tok else: - stmt = stmt_class(string, set_vars, used_funcs, used_vars, \ + stmt = stmt_class(string, set_vars, used_funcs, used_vars, tok_list, first_pos, self.end_pos) self._check_user_stmt(stmt) if is_return: