forked from VimPlug/jedi
Fix bytes issue with file path adding
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
|
||||
from jedi._compatibility import FileNotFoundError
|
||||
from jedi._compatibility import FileNotFoundError, force_unicode
|
||||
from jedi.evaluate.names import AbstractArbitraryName
|
||||
from jedi.api import classes
|
||||
from jedi.evaluate.helpers import get_str_or_none
|
||||
@@ -54,7 +54,7 @@ def _get_string_additions(module_context, start_leaf):
|
||||
s = get_str_or_none(c)
|
||||
if s is None:
|
||||
return string
|
||||
string = s + string
|
||||
string = force_unicode(s) + string
|
||||
continue
|
||||
|
||||
if child_node != '+':
|
||||
|
||||
@@ -27,8 +27,9 @@ class _ModuleAttributeName(AbstractNameDefinition):
|
||||
def infer(self):
|
||||
if self._string_value is not None:
|
||||
s = self._string_value
|
||||
if self.parent_context.evaluator.environment.version_info.major == 2:
|
||||
s = bytes(s)
|
||||
if self.parent_context.evaluator.environment.version_info.major == 2 \
|
||||
and not isinstance(s, bytes):
|
||||
s = bytes(s, 'utf-8')
|
||||
return ContextSet([
|
||||
create_simple_object(self.parent_context.evaluator, s)
|
||||
])
|
||||
|
||||
@@ -195,6 +195,9 @@ def test_keyword_completion(Script, code, has_keywords):
|
||||
('example.py', 'x = f("te" + "st"', 16, [s]),
|
||||
('example.py', 'x = f("te" + "st")', 16, [s]),
|
||||
('example.py', 'x = f("t" + "est")', 16, [s]),
|
||||
# This is actually not correct, but for now leave it here, because of
|
||||
# Python 2.
|
||||
('example.py', 'x = f(b"t" + "est")', 17, [s]),
|
||||
('example.py', '"test" + "', None, [s]),
|
||||
]
|
||||
)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
from jedi._compatibility import force_unicode
|
||||
|
||||
|
||||
def test_module_attributes(Script):
|
||||
def_, = Script('__name__').completions()
|
||||
assert def_.name == '__name__'
|
||||
@@ -10,9 +13,9 @@ def test_module_attributes(Script):
|
||||
def test_module__file__(Script, environment):
|
||||
assert not Script('__file__').goto_definitions()
|
||||
def_, = Script('__file__', path='example.py').goto_definitions()
|
||||
value = def_._name._context.get_safe_value()
|
||||
value = force_unicode(def_._name._context.get_safe_value())
|
||||
assert value.endswith('example.py')
|
||||
|
||||
def_, = Script('import antigravity; antigravity.__file__').goto_definitions()
|
||||
value = def_._name._context.get_safe_value()
|
||||
value = force_unicode(def_._name._context.get_safe_value())
|
||||
assert value.endswith('.py')
|
||||
|
||||
Reference in New Issue
Block a user