Fix Python 3 with Python 2 environment issues

This commit is contained in:
Dave Halter
2018-12-16 17:13:02 +01:00
parent f55da1e1d6
commit af51c9cc33
2 changed files with 7 additions and 4 deletions

View File

@@ -3,7 +3,7 @@ We need to somehow work with the typing objects. Since the typing objects are
pretty bare we need to add all the Jedi customizations to make them work as
contexts.
"""
from jedi._compatibility import unicode
from jedi._compatibility import unicode, force_unicode
from jedi import debug
from jedi.evaluate.cache import evaluator_method_cache
from jedi.evaluate.compiled import builtin_from_name
@@ -376,6 +376,9 @@ class TypeVarClass(_BaseTypingContext):
return None
else:
safe_value = method(default=None)
if self.evaluator.environment.version_info.major == 2:
if isinstance(safe_value, bytes):
return force_unicode(safe_value)
if isinstance(safe_value, (str, unicode)):
return safe_value
return None

View File

@@ -403,13 +403,13 @@ def collections_namedtuple(obj, arguments):
# Process arguments
# TODO here we only use one of the types, we should use all.
# TODO this is buggy, doesn't need to be a string
name = list(_follow_param(evaluator, arguments, 0))[0].get_safe_value()
name = force_unicode(list(_follow_param(evaluator, arguments, 0))[0].get_safe_value())
_fields = list(_follow_param(evaluator, arguments, 1))[0]
if isinstance(_fields, compiled.CompiledValue):
fields = _fields.get_safe_value().replace(',', ' ').split()
fields = force_unicode(_fields.get_safe_value()).replace(',', ' ').split()
elif isinstance(_fields, iterable.Sequence):
fields = [
v.get_safe_value()
force_unicode(v.get_safe_value())
for lazy_context in _fields.py__iter__()
for v in lazy_context.infer() if is_string(v)
]