1
0
forked from VimPlug/jedi

Fix some more py36 to py27 issues

This commit is contained in:
Dave Halter
2017-12-28 01:33:51 +01:00
parent a8d3c46e9d
commit a7dea9e821
3 changed files with 16 additions and 11 deletions

View File

@@ -448,6 +448,8 @@ class FakeDict(_FakeArray):
yield LazyKnownContext(compiled.create_simple_object(self.evaluator, key)) yield LazyKnownContext(compiled.create_simple_object(self.evaluator, key))
def py__getitem__(self, index): def py__getitem__(self, index):
if isinstance(index, bytes):
index = force_unicode(index)
return self._dct[index].infer() return self._dct[index].infer()
def dict_values(self): def dict_values(self):

View File

@@ -269,8 +269,8 @@ class DictFilter(AbstractFilter):
value = self._convert(name, self._dct[name]) value = self._convert(name, self._dct[name])
except KeyError: except KeyError:
return [] return []
else:
return list(self._filter([value])) return list(self._filter([value]))
def values(self): def values(self):
return self._filter(self._convert(*item) for item in self._dct.items()) return self._filter(self._convert(*item) for item in self._dct.items())
@@ -306,7 +306,12 @@ class SpecialMethodFilter(DictFilter):
class SpecialMethodName(AbstractNameDefinition): class SpecialMethodName(AbstractNameDefinition):
api_type = u'function' api_type = u'function'
def __init__(self, parent_context, string_name, callable_, builtin_context): def __init__(self, parent_context, string_name, value, builtin_context):
callable_, python_version = value
if python_version is not None and \
python_version != parent_context.evaluator.environment.version_info.major:
raise KeyError
self.parent_context = parent_context self.parent_context = parent_context
self.string_name = string_name self.string_name = string_name
self._callable = callable_ self._callable = callable_
@@ -355,14 +360,11 @@ def has_builtin_methods(cls):
def register_builtin_method(method_name, python_version_match=None): def register_builtin_method(method_name, python_version_match=None):
def wrapper(func): def decorator(func):
if python_version_match and python_version_match != 2 + int(is_py3):
# Some functions do only apply to certain versions.
return func
dct = func.__dict__.setdefault('registered_builtin_methods', {}) dct = func.__dict__.setdefault('registered_builtin_methods', {})
dct[method_name] = func dct[method_name] = func, python_version_match
return func return func
return wrapper return decorator
def get_global_filters(evaluator, context, until_position, origin_scope): def get_global_filters(evaluator, context, until_position, origin_scope):

View File

@@ -1,7 +1,7 @@
import os import os
import imp import imp
from jedi._compatibility import unicode from jedi._compatibility import unicode, force_unicode
from jedi.evaluate.cache import evaluator_method_cache from jedi.evaluate.cache import evaluator_method_cache
from jedi.evaluate.base_context import ContextualizedNode from jedi.evaluate.base_context import ContextualizedNode
from jedi.evaluate.helpers import is_string from jedi.evaluate.helpers import is_string
@@ -11,16 +11,17 @@ from jedi.evaluate.utils import ignored
def _abs_path(module_context, path): def _abs_path(module_context, path):
module_path = module_context.py__file__()
if os.path.isabs(path): if os.path.isabs(path):
return path return path
module_path = module_context.py__file__()
if module_path is None: if module_path is None:
# In this case we have no idea where we actually are in the file # In this case we have no idea where we actually are in the file
# system. # system.
return None return None
base_dir = os.path.dirname(module_path) base_dir = os.path.dirname(module_path)
path = force_unicode(path)
return os.path.abspath(os.path.join(base_dir, path)) return os.path.abspath(os.path.join(base_dir, path))