mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
catched some errors of invalid code, that was caused by imbalanced closing brackets
This commit is contained in:
@@ -205,6 +205,12 @@ def prepare_goto(source, position, source_path, module, goto_path,
|
||||
debug.dbg('start: %s in %s' % (goto_path, scope))
|
||||
|
||||
user_stmt = module.parser.user_stmt
|
||||
if not user_stmt and len(goto_path.split('\n')) > 1:
|
||||
# If the user_stmt is not defined and the goto_path is multi line,
|
||||
# something's strange. Most probably the backwards tokenizer matched to
|
||||
# much.
|
||||
return []
|
||||
|
||||
if isinstance(user_stmt, parsing.Import):
|
||||
scopes = [imports.ImportPath(user_stmt, is_like_search)]
|
||||
else:
|
||||
|
||||
57
modules.py
57
modules.py
@@ -1,9 +1,11 @@
|
||||
from __future__ import with_statement
|
||||
import re
|
||||
import tokenize
|
||||
import sys
|
||||
|
||||
import parsing
|
||||
import builtin
|
||||
import debug
|
||||
|
||||
files = {}
|
||||
load_module_cb = None
|
||||
@@ -63,7 +65,7 @@ class ModuleWithCursor(Module):
|
||||
else:
|
||||
line = line + '\n'
|
||||
# add lines with a backslash at the end
|
||||
while self._line_temp > 1:
|
||||
while 1:
|
||||
self._line_temp -= 1
|
||||
last_line = self.get_line(self._line_temp)
|
||||
if last_line and last_line[-1] == '\\':
|
||||
@@ -81,34 +83,37 @@ class ModuleWithCursor(Module):
|
||||
gen = tokenize.generate_tokens(fetch_line)
|
||||
string = ''
|
||||
level = 0
|
||||
for token_type, tok, start, end, line in gen:
|
||||
#print token_type, tok, force_point
|
||||
if level > 0:
|
||||
if tok in close_brackets:
|
||||
level += 1
|
||||
if tok in open_brackets:
|
||||
level -= 1
|
||||
elif tok == '.':
|
||||
force_point = False
|
||||
elif force_point:
|
||||
# it is reversed, therefore a number is getting recognized
|
||||
# as a floating point number
|
||||
if token_type == tokenize.NUMBER and tok[0] == '.':
|
||||
try:
|
||||
for token_type, tok, start, end, line in gen:
|
||||
#print token_type, tok, force_point
|
||||
if level > 0:
|
||||
if tok in close_brackets:
|
||||
level += 1
|
||||
if tok in open_brackets:
|
||||
level -= 1
|
||||
elif tok == '.':
|
||||
force_point = False
|
||||
elif force_point:
|
||||
# it is reversed, therefore a number is getting recognized
|
||||
# as a floating point number
|
||||
if token_type == tokenize.NUMBER and tok[0] == '.':
|
||||
force_point = False
|
||||
else:
|
||||
#print 'break2', token_type, tok
|
||||
break
|
||||
elif tok in close_brackets:
|
||||
level += 1
|
||||
elif token_type in [tokenize.NAME, tokenize.STRING]:
|
||||
force_point = True
|
||||
elif token_type == tokenize.NUMBER:
|
||||
pass
|
||||
else:
|
||||
#print 'break2', token_type, tok
|
||||
#print 'break', token_type, tok
|
||||
break
|
||||
elif tok in close_brackets:
|
||||
level += 1
|
||||
elif token_type in [tokenize.NAME, tokenize.STRING]:
|
||||
force_point = True
|
||||
elif token_type == tokenize.NUMBER:
|
||||
pass
|
||||
else:
|
||||
#print 'break', token_type, tok
|
||||
break
|
||||
|
||||
string += tok
|
||||
string += tok
|
||||
except tokenize.TokenError:
|
||||
debug.warning("Tokenize couldn't finish", sys.exc_info)
|
||||
|
||||
return string[::-1]
|
||||
|
||||
@@ -125,6 +130,8 @@ class ModuleWithCursor(Module):
|
||||
if not self._line_cache:
|
||||
self._line_cache = self.source.split('\n')
|
||||
|
||||
if line < 1:
|
||||
raise StopIteration()
|
||||
try:
|
||||
return self._line_cache[line - 1]
|
||||
except IndexError:
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#? ['message']
|
||||
AttributeError()).message
|
||||
|
||||
from a import (b
|
||||
def blub():
|
||||
return 0
|
||||
@@ -53,5 +56,5 @@ try:
|
||||
#? str()
|
||||
""
|
||||
|
||||
#? ['lala']
|
||||
isinstance())
|
||||
#? []
|
||||
int()).
|
||||
|
||||
Reference in New Issue
Block a user