diff --git a/jedi/parser/fast.py b/jedi/parser/fast.py index f7e17a43..3a6ab5d5 100644 --- a/jedi/parser/fast.py +++ b/jedi/parser/fast.py @@ -12,9 +12,11 @@ from jedi.parser import Parser from jedi.parser import tree as pr from jedi.parser import tokenize from jedi import cache -from jedi.parser.tokenize import (source_tokens, FLOWS, NEWLINE, +from jedi.parser.tokenize import (source_tokens, NEWLINE, ENDMARKER, INDENT, DEDENT) +FLOWS = ['if', 'else', 'elif', 'while', 'with', 'try', 'except', 'finally', 'for'] + class FastModule(pr.SubModule): type = 'file_input' @@ -278,7 +280,7 @@ class ParserNode(object): class FastParser(use_metaclass(CachedFastParser)): - _keyword_re = re.compile('^[ \t]*(def|class|@|%s)' % '|'.join(tokenize.FLOWS)) + _keyword_re = re.compile('^[ \t]*(def|class|@|%s)' % '|'.join(FLOWS)) def __init__(self, grammar, source, module_path=None): # set values like `pr.Module`. @@ -348,7 +350,7 @@ class FastParser(use_metaclass(CachedFastParser)): if not in_flow: m = self._keyword_re.match(l) if m: - in_flow = m.group(1) in tokenize.FLOWS + in_flow = m.group(1) in FLOWS if not is_decorator and not in_flow: if current_lines: yield gen_part() @@ -540,7 +542,6 @@ class FastTokenizer(object): self._indent_counter += 1 elif typ == DEDENT: self._indent_counter -= 1 - print(self._flow_indent_counter) if self._in_flow and self._indent_counter == self._flow_indent_counter: self._in_flow = False self._next_dedent_noclose = True diff --git a/jedi/parser/tokenize.py b/jedi/parser/tokenize.py index b009c13f..3240082c 100644 --- a/jedi/parser/tokenize.py +++ b/jedi/parser/tokenize.py @@ -21,11 +21,6 @@ from jedi.parser.token import (tok_name, N_TOKENS, ENDMARKER, STRING, NUMBER, cookie_re = re.compile("coding[:=]\s*([-\w.]+)") -# From here on we have custom stuff (everything before was originally Python -# internal code). -FLOWS = ['if', 'else', 'elif', 'while', 'with', 'try', 'except', 'finally'] - - namechars = string.ascii_letters + '_' diff --git a/test/test_parser/test_fast_parser.py b/test/test_parser/test_fast_parser.py index 36ebb4f0..d7b9bc08 100644 --- a/test/test_parser/test_fast_parser.py +++ b/test/test_parser/test_fast_parser.py @@ -131,6 +131,17 @@ def test_if_simple(): check_fp(src + "else:\n a = ''\na", 1) +def test_for(): + src = dedent("""\ + for a in [1,2]: + a + + for a1 in 1,"": + a1 + """) + check_fp(src, 1) + + def test_incomplete_function(): source = '''return ImportErr'''