From 6a2a2a9fa1d4fbbebf413a9f34da5320a8ad0c7f Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 30 Sep 2018 13:26:54 +0200 Subject: [PATCH] Fix an issue with f-strings, fixes #1224 --- jedi/api/helpers.py | 11 +++++++---- test/completion/fstring.py | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/jedi/api/helpers.py b/jedi/api/helpers.py index fda8d1c2..2489cd9b 100644 --- a/jedi/api/helpers.py +++ b/jedi/api/helpers.py @@ -105,14 +105,17 @@ def get_stack_at_position(grammar, code_lines, module_node, pos): # TODO This is for now not an official parso API that exists purely # for Jedi. tokens = grammar._tokenize(code) - for token_ in tokens: - if token_.string == safeword: + for token in tokens: + if token.string == safeword: raise EndMarkerReached() - elif token_.prefix.endswith(safeword): + elif token.prefix.endswith(safeword): # This happens with comments. raise EndMarkerReached() + elif token.string.endswith(safeword): + yield token # Probably an f-string literal that was not finished. + raise EndMarkerReached() else: - yield token_ + yield token # The code might be indedented, just remove it. code = dedent(_get_code_for_stack(code_lines, module_node, pos)) diff --git a/test/completion/fstring.py b/test/completion/fstring.py index 818ee27f..97cc1cc0 100644 --- a/test/completion/fstring.py +++ b/test/completion/fstring.py @@ -28,3 +28,7 @@ Fr'''sasdf''' + '' #? ['upper'] f'xyz'.uppe + + +#? 3 [] +f'f'