forked from VimPlug/jedi
Fix some fstring issues for now
This commit is contained in:
@@ -11,6 +11,8 @@ from parso.python import tree
|
|||||||
from jedi._compatibility import u
|
from jedi._compatibility import u
|
||||||
from jedi.evaluate.syntax_tree import eval_atom
|
from jedi.evaluate.syntax_tree import eval_atom
|
||||||
from jedi.evaluate.helpers import evaluate_call_of_leaf
|
from jedi.evaluate.helpers import evaluate_call_of_leaf
|
||||||
|
from jedi.evaluate.compiled import get_string_context_set
|
||||||
|
from jedi.evaluate.base_context import ContextSet
|
||||||
from jedi.cache import time_cache
|
from jedi.cache import time_cache
|
||||||
|
|
||||||
|
|
||||||
@@ -193,6 +195,8 @@ def evaluate_goto_definition(evaluator, context, leaf):
|
|||||||
return evaluate_call_of_leaf(context, leaf)
|
return evaluate_call_of_leaf(context, leaf)
|
||||||
elif isinstance(leaf, tree.Literal):
|
elif isinstance(leaf, tree.Literal):
|
||||||
return eval_atom(context, leaf)
|
return eval_atom(context, leaf)
|
||||||
|
elif leaf.type == 'fstring_string':
|
||||||
|
return get_string_context_set(evaluator)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ def get_special_object(evaluator, identifier):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_string_context_set(evaluator):
|
||||||
|
return builtin_from_name(evaluator, u'str').execute_evaluated()
|
||||||
|
|
||||||
|
|
||||||
def load_module(evaluator, **kwargs):
|
def load_module(evaluator, **kwargs):
|
||||||
access_path = evaluator.compiled_subprocess.load_module(**kwargs)
|
access_path = evaluator.compiled_subprocess.load_module(**kwargs)
|
||||||
if access_path is None:
|
if access_path is None:
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ class _ModuleAttributeName(AbstractNameDefinition):
|
|||||||
self.string_name = string_name
|
self.string_name = string_name
|
||||||
|
|
||||||
def infer(self):
|
def infer(self):
|
||||||
ctx = compiled.builtin_from_name(self.parent_context.evaluator, u'str')
|
return compiled.get_string_context_set(self.parent_context.evaluator)
|
||||||
return ctx.execute_evaluated()
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleName(ContextNameMixin, AbstractNameDefinition):
|
class ModuleName(ContextNameMixin, AbstractNameDefinition):
|
||||||
|
|||||||
@@ -23,5 +23,5 @@ Fr'a{Foo.bar'
|
|||||||
#? str()
|
#? str()
|
||||||
Fr'sasdf'
|
Fr'sasdf'
|
||||||
|
|
||||||
#? 7 str()
|
#? 7
|
||||||
Fr'''sasdf''' + ''
|
Fr'''sasdf''' + ''
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
from jedi.evaluate.context import CompiledInstance
|
||||||
|
|
||||||
|
|
||||||
def _eval_literal(Script, code):
|
def _eval_literal(Script, code, *, is_fstring=False):
|
||||||
def_, = Script(code).goto_definitions()
|
def_, = Script(code).goto_definitions()
|
||||||
return def_._name._context.get_safe_value()
|
if is_fstring:
|
||||||
|
assert def_.name == 'str'
|
||||||
|
assert isinstance(def_._name._context, CompiledInstance)
|
||||||
|
return ''
|
||||||
|
else:
|
||||||
|
return def_._name._context.get_safe_value()
|
||||||
|
|
||||||
|
|
||||||
def test_f_strings(Script, environment):
|
def test_f_strings(Script, environment):
|
||||||
@@ -14,10 +20,10 @@ def test_f_strings(Script, environment):
|
|||||||
if environment.version_info < (3, 6):
|
if environment.version_info < (3, 6):
|
||||||
pytest.skip()
|
pytest.skip()
|
||||||
|
|
||||||
assert _eval_literal(Script, 'f"asdf"') == ''
|
assert _eval_literal(Script, 'f"asdf"', is_fstring=True) == ''
|
||||||
assert _eval_literal(Script, 'f"{asdf}"') == ''
|
assert _eval_literal(Script, 'f"{asdf} "', is_fstring=True) == ''
|
||||||
assert _eval_literal(Script, 'F"{asdf}"') == ''
|
assert _eval_literal(Script, 'F"{asdf} "', is_fstring=True) == ''
|
||||||
assert _eval_literal(Script, 'rF"{asdf}"') == ''
|
assert _eval_literal(Script, 'rF"{asdf} "', is_fstring=True) == ''
|
||||||
|
|
||||||
|
|
||||||
def test_rb_strings(Script, environment):
|
def test_rb_strings(Script, environment):
|
||||||
|
|||||||
Reference in New Issue
Block a user