From afca0ef0476a758f71ba798a2c1972f831ad01da Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 30 Oct 2014 01:56:08 +0100 Subject: [PATCH] The user context parser should ignore keywords if they are not standing alone. --- jedi/api/__init__.py | 4 +--- jedi/parser/user_context.py | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 522844ac..6808f9a8 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -280,9 +280,7 @@ class Script(object): stmt = r.module.statements[-1] except IndexError: raise NotFoundError() - if isinstance(stmt, pr.KeywordStatement): - stmt = stmt.stmt - if not isinstance(stmt, pr.ExprStmt): + if not isinstance(stmt, (pr.ExprStmt, pr.KeywordStatement)): raise NotFoundError() user_stmt = self._parser.user_stmt() diff --git a/jedi/parser/user_context.py b/jedi/parser/user_context.py index 4637039f..86377c1f 100644 --- a/jedi/parser/user_context.py +++ b/jedi/parser/user_context.py @@ -1,5 +1,6 @@ import re import os +import keyword from jedi import cache from jedi import common @@ -104,6 +105,10 @@ class UserContext(object): elif tok_str in close_brackets: level += 1 elif tok_type in [tokenize.NAME, tokenize.STRING]: + if keyword.iskeyword(tok_str[::-1]) and string: + # If there's already something in the string, a keyword + # never adds any meaning to the current statement. + break force_point = True elif tok_type == tokenize.NUMBER: pass