From fcd8b25d3dc91529b47c7a0796b9d4beeb272125 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 4 May 2014 12:32:02 +0200 Subject: [PATCH] the parser in general now cares for carriage return/new line combinations --- jedi/evaluate/imports.py | 1 - jedi/parser/__init__.py | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index 073d64af..7c10e5bc 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -408,7 +408,6 @@ class _Importer(object): path += '/__init__.py' with open(path, 'rb') as f: source = f.read() - source = source.replace(b'\n', b'\r\n') else: source = current_namespace[0].read() current_namespace[0].close() diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index 111abc1c..3dbfa207 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -146,7 +146,7 @@ class Parser(object): """ imports = [] brackets = False - continue_kw = [",", ";", "\n", ')'] \ + continue_kw = [",", ";", "\n", '\r\n', ')'] \ + list(set(keyword.kwlist) - set(['as'])) while True: defunct = False @@ -154,7 +154,7 @@ class Parser(object): if tok.string == '(': # python allows only one `(` in the statement. brackets = True tok = next(self._gen) - if brackets and tok.string == '\n': + if brackets and tok.type == tokenize.NEWLINE: tok = next(self._gen) i, tok = self._parse_dot_name(tok) if not i: @@ -165,7 +165,7 @@ class Parser(object): imports.append((i, name2, defunct)) while tok.string not in continue_kw: tok = next(self._gen) - if not (tok.string == "," or brackets and tok.string == '\n'): + if not (tok.string == "," or brackets and tok.type == tokenize.NEWLINE): break return imports @@ -302,7 +302,7 @@ class Parser(object): # will even break in parentheses. This is true for typical flow # commands like def and class and the imports, which will never be used # in a statement. - breaks = set(['\n', ':', ')']) + breaks = set(['\n', '\r\n', ':', ')']) always_break = [';', 'import', 'from', 'class', 'def', 'try', 'except', 'finally', 'while', 'return', 'yield'] not_first_break = ['del', 'raise'] @@ -515,7 +515,7 @@ class Parser(object): # multiple inputs because of with inputs = [] first = True - while first or command == 'with' and tok.string not in (':', '\n'): + while first or command == 'with' and tok.string not in (':', '\n', '\r\n'): statement, tok = \ self._parse_statement(added_breaks=added_breaks) if command == 'except' and tok.string == ',':