From ede685c717f8fd992311a2c5c7b53e5205b05871 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 1 Jul 2014 01:19:07 +0200 Subject: [PATCH] string prefixes are now recognized by the backwards tokenizer --- jedi/parser/user_context.py | 9 ++++++--- test/test_evaluate/test_compiled.py | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/jedi/parser/user_context.py b/jedi/parser/user_context.py index 8a202b7c..5fcbd1c3 100644 --- a/jedi/parser/user_context.py +++ b/jedi/parser/user_context.py @@ -91,9 +91,12 @@ class UserContext(object): elif tok_str == '.': force_point = False elif force_point: - # it is reversed, therefore a number is getting recognized - # as a floating point number - if tok_type == tokenize.NUMBER and tok_str[0] == '.': + # Reversed tokenizing, therefore a number is recognized as a + # floating point number. + # The same is true for string prefixes -> represented as a + # combination of string and name. + if tok_type == tokenize.NUMBER and tok_str[0] == '.' \ + or tok_type == tokenize.NAME and last_type == tokenize.STRING: force_point = False else: break diff --git a/test/test_evaluate/test_compiled.py b/test/test_evaluate/test_compiled.py index 3a0490c7..449dce3d 100644 --- a/test/test_evaluate/test_compiled.py +++ b/test/test_evaluate/test_compiled.py @@ -1,7 +1,8 @@ -from jedi._compatibility import builtins +from jedi._compatibility import builtins, is_py3 from jedi.parser.representation import Function from jedi.evaluate import compiled from jedi.evaluate import Evaluator +from jedi import Script def test_simple(): @@ -47,3 +48,19 @@ def test_doc(): """ obj = compiled.CompiledObject(''.__getnewargs__) assert obj.doc == '' + + +def test_string_literals(): + def typ(string): + d = Script(string).goto_definitions()[0] + return d.name + + assert typ('""') == 'str' + assert typ('r""') == 'str' + if is_py3: + assert typ('br""') == 'bytes' + assert typ('b""') == 'bytes' + assert typ('u""') == 'str' + else: + assert typ('b""') == 'string' + assert typ('u""') == 'unicode'