forked from VimPlug/jedi
Fix most flake8 issues (fixes #205)
This commit is contained in:
@@ -18,6 +18,7 @@ is_py3k = sys.hexversion >= 0x03000000
|
|||||||
is_py33 = sys.hexversion >= 0x03030000
|
is_py33 = sys.hexversion >= 0x03030000
|
||||||
is_py25 = sys.hexversion < 0x02060000
|
is_py25 = sys.hexversion < 0x02060000
|
||||||
|
|
||||||
|
|
||||||
def find_module_py33(string, path=None):
|
def find_module_py33(string, path=None):
|
||||||
mod_info = (None, None, None)
|
mod_info = (None, None, None)
|
||||||
loader = None
|
loader = None
|
||||||
@@ -48,6 +49,7 @@ def find_module_py33(string, path=None):
|
|||||||
|
|
||||||
return mod_info
|
return mod_info
|
||||||
|
|
||||||
|
|
||||||
def find_module_pre_py33(string, path=None):
|
def find_module_pre_py33(string, path=None):
|
||||||
mod_info = None
|
mod_info = None
|
||||||
if path is None:
|
if path is None:
|
||||||
@@ -57,6 +59,7 @@ def find_module_pre_py33(string, path=None):
|
|||||||
|
|
||||||
return (mod_info[0], mod_info[1], mod_info[2][2] == imp.PKG_DIRECTORY)
|
return (mod_info[0], mod_info[1], mod_info[2][2] == imp.PKG_DIRECTORY)
|
||||||
|
|
||||||
|
|
||||||
def find_module(string, path=None):
|
def find_module(string, path=None):
|
||||||
"""Provides information about a module.
|
"""Provides information about a module.
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ def _clear_caches_after_call(func):
|
|||||||
|
|
||||||
|
|
||||||
class BaseDefinition(object):
|
class BaseDefinition(object):
|
||||||
_mapping = {'posixpath': 'os.path',
|
_mapping = {
|
||||||
|
'posixpath': 'os.path',
|
||||||
'riscospath': 'os.path',
|
'riscospath': 'os.path',
|
||||||
'ntpath': 'os.path',
|
'ntpath': 'os.path',
|
||||||
'os2emxpath': 'os.path',
|
'os2emxpath': 'os.path',
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ def warning(*args):
|
|||||||
|
|
||||||
def speed(name):
|
def speed(name):
|
||||||
if debug_function and enable_speed:
|
if debug_function and enable_speed:
|
||||||
|
global start_time
|
||||||
now = time.time()
|
now = time.time()
|
||||||
debug_function(SPEED, 'speed: ' + '%s %s' % (name, now - start_time))
|
debug_function(SPEED, 'speed: ' + '%s %s' % (name, now - start_time))
|
||||||
|
|
||||||
|
|||||||
@@ -529,7 +529,7 @@ def check_statement_information(stmt, search_name):
|
|||||||
# isinstance check
|
# isinstance check
|
||||||
isinst = call.execution.values
|
isinst = call.execution.values
|
||||||
assert len(isinst) == 2 # has two params
|
assert len(isinst) == 2 # has two params
|
||||||
obj, classes = [stmt.get_commands() for stmt in isinst]
|
obj, classes = [statement.get_commands() for statement in isinst]
|
||||||
assert len(obj) == 1
|
assert len(obj) == 1
|
||||||
assert len(classes) == 1
|
assert len(classes) == 1
|
||||||
assert isinstance(obj[0], pr.Call)
|
assert isinstance(obj[0], pr.Call)
|
||||||
|
|||||||
@@ -41,13 +41,15 @@ class Module(pr.Simple, pr.Module):
|
|||||||
return self.cache[key]
|
return self.cache[key]
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
operators = {'get_imports': operator.add,
|
operators = {
|
||||||
|
'get_imports': operator.add,
|
||||||
'get_code': operator.add,
|
'get_code': operator.add,
|
||||||
'get_set_vars': operator.add,
|
'get_set_vars': operator.add,
|
||||||
'get_defined_names': operator.add,
|
'get_defined_names': operator.add,
|
||||||
'is_empty': operator.and_
|
'is_empty': operator.and_
|
||||||
}
|
}
|
||||||
properties = {'subscopes': operator.add,
|
properties = {
|
||||||
|
'subscopes': operator.add,
|
||||||
'imports': operator.add,
|
'imports': operator.add,
|
||||||
'statements': operator.add,
|
'statements': operator.add,
|
||||||
'imports': operator.add,
|
'imports': operator.add,
|
||||||
|
|||||||
@@ -401,10 +401,10 @@ class Parser(object):
|
|||||||
with common.ignored(IndexError, AttributeError):
|
with common.ignored(IndexError, AttributeError):
|
||||||
# If string literal is being parsed
|
# If string literal is being parsed
|
||||||
first_tok = stmt.token_list[0]
|
first_tok = stmt.token_list[0]
|
||||||
if (not stmt.set_vars and
|
if (not stmt.set_vars
|
||||||
not stmt.used_vars and
|
and not stmt.used_vars
|
||||||
len(stmt.token_list) == 1 and
|
and len(stmt.token_list) == 1
|
||||||
first_tok[0] == tokenize.STRING):
|
and first_tok[0] == tokenize.STRING):
|
||||||
# ... then set it as a docstring
|
# ... then set it as a docstring
|
||||||
self.scope.statements[-1].add_docstr(first_tok[1])
|
self.scope.statements[-1].add_docstr(first_tok[1])
|
||||||
|
|
||||||
@@ -434,7 +434,7 @@ class Parser(object):
|
|||||||
if self.user_position and (self.start_pos[0] == self.user_position[0]
|
if self.user_position and (self.start_pos[0] == self.user_position[0]
|
||||||
or self.user_scope is None
|
or self.user_scope is None
|
||||||
and self.start_pos[0] >= self.user_position[0]):
|
and self.start_pos[0] >= self.user_position[0]):
|
||||||
debug.dbg('user scope found [%s] = %s' % \
|
debug.dbg('user scope found [%s] = %s' %
|
||||||
(self.parserline.replace('\n', ''), repr(self.scope)))
|
(self.parserline.replace('\n', ''), repr(self.scope)))
|
||||||
self.user_scope = self.scope
|
self.user_scope = self.scope
|
||||||
self.last_token = self.current
|
self.last_token = self.current
|
||||||
|
|||||||
@@ -1272,7 +1272,8 @@ class Array(Call):
|
|||||||
return zip(self.keys, self.values)
|
return zip(self.keys, self.values)
|
||||||
|
|
||||||
def get_code(self):
|
def get_code(self):
|
||||||
map = {self.NOARRAY: '(%s)',
|
map = {
|
||||||
|
self.NOARRAY: '(%s)',
|
||||||
self.TUPLE: '(%s)',
|
self.TUPLE: '(%s)',
|
||||||
self.LIST: '[%s]',
|
self.LIST: '[%s]',
|
||||||
self.DICT: '{%s}',
|
self.DICT: '{%s}',
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class RecursionDecorator(object):
|
|||||||
def push_stmt(self, stmt):
|
def push_stmt(self, stmt):
|
||||||
self.current = RecursionNode(stmt, self.current)
|
self.current = RecursionNode(stmt, self.current)
|
||||||
check = self._check_recursion()
|
check = self._check_recursion()
|
||||||
if check:# TODO remove False!!!!
|
if check: # TODO remove False!!!!
|
||||||
debug.warning('catched stmt recursion: %s against %s @%s'
|
debug.warning('catched stmt recursion: %s against %s @%s'
|
||||||
% (stmt, check.stmt, stmt.start_pos))
|
% (stmt, check.stmt, stmt.start_pos))
|
||||||
self.pop_stmt()
|
self.pop_stmt()
|
||||||
|
|||||||
@@ -26,15 +26,25 @@ ENCODING = N_TOKENS + 2
|
|||||||
tok_name[ENCODING] = 'ENCODING'
|
tok_name[ENCODING] = 'ENCODING'
|
||||||
N_TOKENS += 3
|
N_TOKENS += 3
|
||||||
|
|
||||||
|
|
||||||
class TokenInfo(collections.namedtuple('TokenInfo', 'type string start end line')):
|
class TokenInfo(collections.namedtuple('TokenInfo', 'type string start end line')):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
annotated_type = '%d (%s)' % (self.type, tok_name[self.type])
|
annotated_type = '%d (%s)' % (self.type, tok_name[self.type])
|
||||||
return ('TokenInfo(type=%s, string=%r, start=%r, end=%r, line=%r)' %
|
return ('TokenInfo(type=%s, string=%r, start=%r, end=%r, line=%r)' %
|
||||||
self._replace(type=annotated_type))
|
self._replace(type=annotated_type))
|
||||||
|
|
||||||
def group(*choices): return '(' + '|'.join(choices) + ')'
|
|
||||||
def any(*choices): return group(*choices) + '*'
|
def group(*choices):
|
||||||
def maybe(*choices): return group(*choices) + '?'
|
return '(' + '|'.join(choices) + ')'
|
||||||
|
|
||||||
|
|
||||||
|
def any(*choices):
|
||||||
|
return group(*choices) + '*'
|
||||||
|
|
||||||
|
|
||||||
|
def maybe(*choices):
|
||||||
|
return group(*choices) + '?'
|
||||||
|
|
||||||
|
|
||||||
# Note: we use unicode matching for names ("\w") but ascii matching for
|
# Note: we use unicode matching for names ("\w") but ascii matching for
|
||||||
# number literals.
|
# number literals.
|
||||||
@@ -91,9 +101,11 @@ ContStr = group(r"[bB]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*" +
|
|||||||
PseudoExtras = group(r'\\\r?\n', Comment, Triple)
|
PseudoExtras = group(r'\\\r?\n', Comment, Triple)
|
||||||
PseudoToken = Whitespace + group(PseudoExtras, Number, Funny, ContStr, Name)
|
PseudoToken = Whitespace + group(PseudoExtras, Number, Funny, ContStr, Name)
|
||||||
|
|
||||||
|
|
||||||
def _compile(expr):
|
def _compile(expr):
|
||||||
return re.compile(expr, re.UNICODE)
|
return re.compile(expr, re.UNICODE)
|
||||||
|
|
||||||
|
|
||||||
tokenprog, pseudoprog, single3prog, double3prog = map(
|
tokenprog, pseudoprog, single3prog, double3prog = map(
|
||||||
_compile, (Token, PseudoToken, Single3, Double3))
|
_compile, (Token, PseudoToken, Single3, Double3))
|
||||||
endprogs = {"'": _compile(Single), '"': _compile(Double),
|
endprogs = {"'": _compile(Single), '"': _compile(Double),
|
||||||
@@ -120,14 +132,16 @@ for t in ("'", '"',
|
|||||||
"r'", 'r"', "R'", 'R"',
|
"r'", 'r"', "R'", 'R"',
|
||||||
"b'", 'b"', "B'", 'B"',
|
"b'", 'b"', "B'", 'B"',
|
||||||
"br'", 'br"', "Br'", 'Br"',
|
"br'", 'br"', "Br'", 'Br"',
|
||||||
"bR'", 'bR"', "BR'", 'BR"' ):
|
"bR'", 'bR"', "BR'", 'BR"'):
|
||||||
single_quoted[t] = t
|
single_quoted[t] = t
|
||||||
|
|
||||||
del _compile
|
del _compile
|
||||||
|
|
||||||
tabsize = 8
|
tabsize = 8
|
||||||
|
|
||||||
class TokenError(Exception): pass
|
|
||||||
|
class TokenError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def generate_tokens(readline):
|
def generate_tokens(readline):
|
||||||
@@ -169,13 +183,14 @@ def generate_tokens(readline):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
elif parenlev == 0 and not continued: # new statement
|
elif parenlev == 0 and not continued: # new statement
|
||||||
if not line: break
|
if not line:
|
||||||
|
break
|
||||||
column = 0
|
column = 0
|
||||||
while pos < max: # measure leading whitespace
|
while pos < max: # measure leading whitespace
|
||||||
if line[pos] == ' ':
|
if line[pos] == ' ':
|
||||||
column += 1
|
column += 1
|
||||||
elif line[pos] == '\t':
|
elif line[pos] == '\t':
|
||||||
column = (column//tabsize + 1)*tabsize
|
column = (column // tabsize + 1) * tabsize
|
||||||
elif line[pos] == '\f':
|
elif line[pos] == '\f':
|
||||||
column = 0
|
column = 0
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user