mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
cleaning / pep8
This commit is contained in:
@@ -8,11 +8,12 @@ try:
|
|||||||
next = next
|
next = next
|
||||||
except NameError:
|
except NameError:
|
||||||
_raiseStopIteration = object()
|
_raiseStopIteration = object()
|
||||||
|
|
||||||
def next(iterator, default=_raiseStopIteration):
|
def next(iterator, default=_raiseStopIteration):
|
||||||
if not hasattr(iterator, 'next'):
|
if not hasattr(iterator, 'next'):
|
||||||
raise TypeError("not an iterator")
|
raise TypeError("not an iterator")
|
||||||
try:
|
try:
|
||||||
return iterator.next()
|
return iterator.next()
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
if default is _raiseStopIteration:
|
if default is _raiseStopIteration:
|
||||||
raise
|
raise
|
||||||
|
|||||||
10
builtin.py
10
builtin.py
@@ -36,10 +36,6 @@ class CachedModule(object):
|
|||||||
def _load_module(self):
|
def _load_module(self):
|
||||||
source = self._get_source()
|
source = self._get_source()
|
||||||
self._parser = parsing.PyFuzzyParser(source, self.path or self.name)
|
self._parser = parsing.PyFuzzyParser(source, self.path or self.name)
|
||||||
#except:
|
|
||||||
# debug.warning('not possible to resolve', self.name, source)
|
|
||||||
#open('builtin_fail', 'w').write(code)
|
|
||||||
# raise
|
|
||||||
p_time = None if not self.path else os.path.getmtime(self.path)
|
p_time = None if not self.path else os.path.getmtime(self.path)
|
||||||
|
|
||||||
self.cache[self.path or self.name] = p_time, self._parser
|
self.cache[self.path or self.name] = p_time, self._parser
|
||||||
@@ -163,10 +159,10 @@ class Parser(CachedModule):
|
|||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
path = scope.__file__
|
path = scope.__file__
|
||||||
except:
|
except AttributeError:
|
||||||
path = '?'
|
path = '?'
|
||||||
code += '# Generated module %s from %s\n' % (scope.__name__, path)
|
code += '# Generated module %s from %s\n' % (scope.__name__, path)
|
||||||
except:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
code += '"""\n%s\n"""\n' % scope.__doc__
|
code += '"""\n%s\n"""\n' % scope.__doc__
|
||||||
|
|
||||||
@@ -189,7 +185,7 @@ class Parser(CachedModule):
|
|||||||
doc_str = parsing.indent_block('"""\n%s\n"""\n' % func.__doc__)
|
doc_str = parsing.indent_block('"""\n%s\n"""\n' % func.__doc__)
|
||||||
try:
|
try:
|
||||||
mixin = self.mixin_funcs[name]
|
mixin = self.mixin_funcs[name]
|
||||||
except:
|
except KeyError:
|
||||||
# normal code generation
|
# normal code generation
|
||||||
code += 'def %s(%s):\n' % (name, params)
|
code += 'def %s(%s):\n' % (name, params)
|
||||||
code += doc_str
|
code += doc_str
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ class Instance(Executable):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return func.params[0].used_vars[0].names[0]
|
return func.params[0].used_vars[0].names[0]
|
||||||
except:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_defined_names(self):
|
def get_defined_names(self):
|
||||||
@@ -414,7 +414,7 @@ class Execution(Executable):
|
|||||||
Get the return vars of a function.
|
Get the return vars of a function.
|
||||||
"""
|
"""
|
||||||
stmts = []
|
stmts = []
|
||||||
#print '\n\n', self.var_args, self.var_args.values, self.var_args.parent_stmt
|
#a = self.var_args; print '\n\n', a, a.values, a.parent_stmt
|
||||||
if isinstance(self.base, Class):
|
if isinstance(self.base, Class):
|
||||||
# there maybe executions of executions
|
# there maybe executions of executions
|
||||||
stmts = [Instance(self.base, self.var_args)]
|
stmts = [Instance(self.base, self.var_args)]
|
||||||
@@ -442,8 +442,8 @@ class Execution(Executable):
|
|||||||
# TODO how can we deactivate this again?
|
# TODO how can we deactivate this again?
|
||||||
#self.base.param_cb = None
|
#self.base.param_cb = None
|
||||||
|
|
||||||
# func could have changed because of decorators, so clear them
|
# func could have changed because of decorators, so clear
|
||||||
# again
|
# them again
|
||||||
self.base.is_decorated = False
|
self.base.is_decorated = False
|
||||||
else:
|
else:
|
||||||
debug.warning("no execution possible", func)
|
debug.warning("no execution possible", func)
|
||||||
@@ -488,6 +488,7 @@ class Generator(object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s of %s>" % (self.__class__.__name__, self.func)
|
return "<%s of %s>" % (self.__class__.__name__, self.func)
|
||||||
|
|
||||||
|
|
||||||
class Array(object):
|
class Array(object):
|
||||||
"""
|
"""
|
||||||
Used as a mirror to parsing.Array, if needed. It defines some getter
|
Used as a mirror to parsing.Array, if needed. It defines some getter
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class Definition(object):
|
|||||||
|
|
||||||
path = str(par.path)
|
path = str(par.path)
|
||||||
try:
|
try:
|
||||||
return path[path.rindex('/')+1:]
|
return path[path.rindex('/') + 1:]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return path
|
return path
|
||||||
|
|
||||||
@@ -107,6 +107,7 @@ class Definition(object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s %s>" % (self.__class__.__name__, self)
|
return "<%s %s>" % (self.__class__.__name__, self)
|
||||||
|
|
||||||
|
|
||||||
def get_completion_parts(path):
|
def get_completion_parts(path):
|
||||||
"""
|
"""
|
||||||
Returns the parts for the completion
|
Returns the parts for the completion
|
||||||
@@ -133,7 +134,8 @@ def complete(source, row, column, source_path):
|
|||||||
:rtype: list
|
:rtype: list
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
scopes, path, dot, like = prepare_goto(source, row, column, source_path, True)
|
scopes, path, dot, like = prepare_goto(source, row, column,
|
||||||
|
source_path, True)
|
||||||
except NotFoundError:
|
except NotFoundError:
|
||||||
# normally this would be used like this: `NotFoundError as exc`, but
|
# normally this would be used like this: `NotFoundError as exc`, but
|
||||||
# this guarantues backwards compatibility with Python2.5.
|
# this guarantues backwards compatibility with Python2.5.
|
||||||
@@ -190,7 +192,7 @@ def prepare_goto(source, row, column, source_path, is_like_search):
|
|||||||
if is_like_search:
|
if is_like_search:
|
||||||
stmt.line_nr = row
|
stmt.line_nr = row
|
||||||
else:
|
else:
|
||||||
stmt.line_nr = row+1
|
stmt.line_nr = row + 1
|
||||||
stmt.indent = column
|
stmt.indent = column
|
||||||
stmt.parent = scope
|
stmt.parent = scope
|
||||||
scopes = evaluate.follow_statement(stmt, scope=scope)
|
scopes = evaluate.follow_statement(stmt, scope=scope)
|
||||||
@@ -200,6 +202,7 @@ def prepare_goto(source, row, column, source_path, is_like_search):
|
|||||||
else:
|
else:
|
||||||
return scopes
|
return scopes
|
||||||
|
|
||||||
|
|
||||||
def get_definitions(source, row, column, source_path):
|
def get_definitions(source, row, column, source_path):
|
||||||
"""
|
"""
|
||||||
Returns the definitions of a the path under the cursor.
|
Returns the definitions of a the path under the cursor.
|
||||||
|
|||||||
Reference in New Issue
Block a user