diff --git a/jedi/evaluate/context/iterable.py b/jedi/evaluate/context/iterable.py index ccdf5db3..3f85ad80 100644 --- a/jedi/evaluate/context/iterable.py +++ b/jedi/evaluate/context/iterable.py @@ -448,6 +448,8 @@ class FakeDict(_FakeArray): yield LazyKnownContext(compiled.create_simple_object(self.evaluator, key)) def py__getitem__(self, index): + if isinstance(index, bytes): + index = force_unicode(index) return self._dct[index].infer() def dict_values(self): diff --git a/jedi/evaluate/filters.py b/jedi/evaluate/filters.py index f7007b71..c9e95998 100644 --- a/jedi/evaluate/filters.py +++ b/jedi/evaluate/filters.py @@ -269,8 +269,8 @@ class DictFilter(AbstractFilter): value = self._convert(name, self._dct[name]) except KeyError: return [] - - return list(self._filter([value])) + else: + return list(self._filter([value])) def values(self): return self._filter(self._convert(*item) for item in self._dct.items()) @@ -306,7 +306,12 @@ class SpecialMethodFilter(DictFilter): class SpecialMethodName(AbstractNameDefinition): 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.string_name = string_name self._callable = callable_ @@ -355,14 +360,11 @@ def has_builtin_methods(cls): def register_builtin_method(method_name, python_version_match=None): - def wrapper(func): - if python_version_match and python_version_match != 2 + int(is_py3): - # Some functions do only apply to certain versions. - return func + def decorator(func): dct = func.__dict__.setdefault('registered_builtin_methods', {}) - dct[method_name] = func + dct[method_name] = func, python_version_match return func - return wrapper + return decorator def get_global_filters(evaluator, context, until_position, origin_scope): diff --git a/jedi/evaluate/sys_path.py b/jedi/evaluate/sys_path.py index 11728430..e34908fe 100644 --- a/jedi/evaluate/sys_path.py +++ b/jedi/evaluate/sys_path.py @@ -1,7 +1,7 @@ import os 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.base_context import ContextualizedNode from jedi.evaluate.helpers import is_string @@ -11,16 +11,17 @@ from jedi.evaluate.utils import ignored def _abs_path(module_context, path): - module_path = module_context.py__file__() if os.path.isabs(path): return path + module_path = module_context.py__file__() if module_path is None: # In this case we have no idea where we actually are in the file # system. return None base_dir = os.path.dirname(module_path) + path = force_unicode(path) return os.path.abspath(os.path.join(base_dir, path))