From 6b63b9cf545c4ef2a6f7d8c984f2af4dee104c2a Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 4 Jun 2016 00:59:17 +0200 Subject: [PATCH] Further fixes for failing tests. --- jedi/api/helpers.py | 7 ++++--- jedi/parser/pgen2/parse.py | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/jedi/api/helpers.py b/jedi/api/helpers.py index c6c30298..6cda2d06 100644 --- a/jedi/api/helpers.py +++ b/jedi/api/helpers.py @@ -125,15 +125,16 @@ def get_stack_at_position(grammar, source, module, pos): user_stmt = get_user_or_error_stmt(module, leaf.start_pos) ''' - if user_stmt.type == 'error_leaf': - # Error leafs cannot be parsed. + if user_stmt.type == 'error_leaf' or user_stmt.type == 'string': + # Error leafs cannot be parsed, completion in strings is also + # impossible. raise OnErrorLeaf(user_stmt) code = _get_code(source, user_stmt.start_pos, pos) # Remove whitespace at the end. Necessary, because the tokenizer will parse # an error token (there's no new line at the end in our case). This doesn't # alter any truth about the valid tokens at that position. - code = code.strip() + code = code.strip('\t ') class EndMarkerReached(Exception): pass diff --git a/jedi/parser/pgen2/parse.py b/jedi/parser/pgen2/parse.py index b6d74852..47573eef 100644 --- a/jedi/parser/pgen2/parse.py +++ b/jedi/parser/pgen2/parse.py @@ -43,7 +43,10 @@ def token_to_ilabel(grammar, type_, value): except KeyError: pass - return grammar.tokens[type_] + try: + return grammar.tokens[type_] + except KeyError: + return None class PgenParser(object):