Fix issues with Python 3.6's f strings and underscores in numbers.

This commit is contained in:
Dave Halter
2017-01-08 19:38:57 +01:00
parent 00a9f1ec0a
commit 7300f3e7ef
6 changed files with 101 additions and 22 deletions

View File

@@ -19,6 +19,17 @@ str..
#? []
a(0):.
# -----------------
# _ separators (for older versions than 3.6, a = 1_2_3 will just be 1, the rest
# gets ignored.)
# -----------------
#? int()
1_2_3
#? int()
123_345_345
#? int()
0x3_4
# -----------------
# if/else/elif
# -----------------

View File

@@ -0,0 +1,37 @@
import pytest
import jedi
from jedi._compatibility import py_version
def _eval_literal(value):
def_, = jedi.Script(value).goto_definitions()
return def_._name._context
@pytest.mark.skipif('sys.version_info[:2] < (3, 6)')
def test_f_strings():
"""
f literals are not really supported in Jedi. They just get ignored and an
empty string is returned.
"""
context = _eval_literal('f"asdf"')
assert context.obj == ''
context = _eval_literal('f"{asdf}"')
assert context.obj == ''
context = _eval_literal('F"{asdf}"')
assert context.obj == ''
context = _eval_literal('rF"{asdf}"')
assert context.obj == ''
def test_rb_strings():
context = _eval_literal('br"asdf"')
assert context.obj == b'asdf'
context = _eval_literal('rb"asdf"')
if py_version < 33:
# Before Python 3.3 there was a more strict definition in which order
# you could define literals.
assert context.obj == ''
else:
assert context.obj == b'asdf'