forked from VimPlug/jedi
invalid list comprehensions should not raise exceptions anymore
This commit is contained in:
21
parsing.py
21
parsing.py
@@ -775,11 +775,9 @@ class Statement(Simple):
|
|||||||
close_brackets = False
|
close_brackets = False
|
||||||
result.add_to_current_field(tok)
|
result.add_to_current_field(tok)
|
||||||
|
|
||||||
#print 'tok_end', tok_temp, result, close_brackets
|
|
||||||
|
|
||||||
if level != 0:
|
if level != 0:
|
||||||
raise ParserError("Brackets don't match: %s. This is not normal "
|
debug.warning("Brackets don't match: %s."
|
||||||
"behaviour. Please submit a bug" % level)
|
"This is not normal behaviour." % level)
|
||||||
|
|
||||||
self._assignment_calls_calculated = True
|
self._assignment_calls_calculated = True
|
||||||
self._assignment_calls = top
|
self._assignment_calls = top
|
||||||
@@ -1317,8 +1315,11 @@ class PyFuzzyParser(object):
|
|||||||
if tok in ['return', 'yield']:
|
if tok in ['return', 'yield']:
|
||||||
is_return = tok
|
is_return = tok
|
||||||
elif tok == 'for':
|
elif tok == 'for':
|
||||||
middle, in_str = self._parse_statement(added_breaks=['in'])
|
# list comprehensions!
|
||||||
if in_str != 'in':
|
middle, tok = self._parse_statement(added_breaks=['in'])
|
||||||
|
if tok != 'in' or middle is None:
|
||||||
|
if middle is None:
|
||||||
|
level -=1
|
||||||
debug.warning('list comprehension formatting @%s' %
|
debug.warning('list comprehension formatting @%s' %
|
||||||
self.start_pos[0])
|
self.start_pos[0])
|
||||||
continue
|
continue
|
||||||
@@ -1326,8 +1327,10 @@ class PyFuzzyParser(object):
|
|||||||
b = [')', ']']
|
b = [')', ']']
|
||||||
in_clause, tok = self._parse_statement(added_breaks=b,
|
in_clause, tok = self._parse_statement(added_breaks=b,
|
||||||
list_comp=True)
|
list_comp=True)
|
||||||
if tok not in b:
|
if tok not in b or in_clause is None:
|
||||||
debug.warning('list comprehension brackets %s@%s' %
|
if in_clause is None:
|
||||||
|
self.gen.push_back(self._current_full)
|
||||||
|
debug.warning('list comprehension in_clause %s@%s' %
|
||||||
(tok, self.start_pos[0]))
|
(tok, self.start_pos[0]))
|
||||||
continue
|
continue
|
||||||
other_level = 0
|
other_level = 0
|
||||||
@@ -1421,7 +1424,7 @@ class PyFuzzyParser(object):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
debug.warning('return in non-function')
|
debug.warning('return in non-function')
|
||||||
|
|
||||||
if list_comp:
|
if list_comp or tok in always_break:
|
||||||
self.gen.push_back(self._current_full)
|
self.gen.push_back(self._current_full)
|
||||||
return stmt, tok
|
return stmt, tok
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
# This file is less about the results and much more about the fact, that no
|
||||||
|
# exception should be thrown.
|
||||||
|
|
||||||
#? ['upper']
|
#? ['upper']
|
||||||
str()).upper
|
str()).upper
|
||||||
|
|
||||||
@@ -31,7 +34,7 @@ def openbrace2():
|
|||||||
def normalfunc():
|
def normalfunc():
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
##? int()
|
#? int()
|
||||||
normalfunc()
|
normalfunc()
|
||||||
|
|
||||||
|
|
||||||
@@ -61,5 +64,32 @@ a = 1 if
|
|||||||
#? int()
|
#? int()
|
||||||
a
|
a
|
||||||
|
|
||||||
|
a2 = [for a2 in [0]]
|
||||||
|
#?
|
||||||
|
a2[0]
|
||||||
|
|
||||||
|
a3 = [for xyz in]
|
||||||
|
#?
|
||||||
|
a3[0]
|
||||||
|
|
||||||
|
a3 = [a4 for in 'b']
|
||||||
|
#? str()
|
||||||
|
a3[0]
|
||||||
|
|
||||||
|
a3 = [a4 for a in for x in y]
|
||||||
|
#?
|
||||||
|
a3[0]
|
||||||
|
|
||||||
|
a = [for a in
|
||||||
|
def break(): pass
|
||||||
|
|
||||||
|
#?
|
||||||
|
a[0]
|
||||||
|
|
||||||
|
a = [a for a in [1,2]
|
||||||
|
def break(): pass
|
||||||
|
#? list()
|
||||||
|
a[0]
|
||||||
|
|
||||||
#? []
|
#? []
|
||||||
int()).
|
int()).
|
||||||
|
|||||||
Reference in New Issue
Block a user