mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Fix Python 3 with Python 2 environment issues
This commit is contained in:
@@ -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
|
pretty bare we need to add all the Jedi customizations to make them work as
|
||||||
contexts.
|
contexts.
|
||||||
"""
|
"""
|
||||||
from jedi._compatibility import unicode
|
from jedi._compatibility import unicode, force_unicode
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.evaluate.cache import evaluator_method_cache
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
from jedi.evaluate.compiled import builtin_from_name
|
from jedi.evaluate.compiled import builtin_from_name
|
||||||
@@ -376,6 +376,9 @@ class TypeVarClass(_BaseTypingContext):
|
|||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
safe_value = method(default=None)
|
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)):
|
if isinstance(safe_value, (str, unicode)):
|
||||||
return safe_value
|
return safe_value
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -403,13 +403,13 @@ def collections_namedtuple(obj, arguments):
|
|||||||
# Process arguments
|
# Process arguments
|
||||||
# TODO here we only use one of the types, we should use all.
|
# TODO here we only use one of the types, we should use all.
|
||||||
# TODO this is buggy, doesn't need to be a string
|
# 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]
|
_fields = list(_follow_param(evaluator, arguments, 1))[0]
|
||||||
if isinstance(_fields, compiled.CompiledValue):
|
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):
|
elif isinstance(_fields, iterable.Sequence):
|
||||||
fields = [
|
fields = [
|
||||||
v.get_safe_value()
|
force_unicode(v.get_safe_value())
|
||||||
for lazy_context in _fields.py__iter__()
|
for lazy_context in _fields.py__iter__()
|
||||||
for v in lazy_context.infer() if is_string(v)
|
for v in lazy_context.infer() if is_string(v)
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user