forked from VimPlug/jedi
Remove a lot more Python 2 mentions and todos
This commit is contained in:
@@ -6,6 +6,7 @@ from collections import namedtuple
|
|||||||
import warnings
|
import warnings
|
||||||
import re
|
import re
|
||||||
import builtins
|
import builtins
|
||||||
|
import typing
|
||||||
|
|
||||||
from jedi.inference.compiled.getattr_static import getattr_static
|
from jedi.inference.compiled.getattr_static import getattr_static
|
||||||
|
|
||||||
@@ -504,15 +505,9 @@ class DirectObjectAccess(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Python 2 doesn't have typing.
|
o = typing.get_type_hints(self._obj).get('return')
|
||||||
import typing
|
except Exception:
|
||||||
except ImportError:
|
|
||||||
pass
|
pass
|
||||||
else:
|
|
||||||
try:
|
|
||||||
o = typing.get_type_hints(self._obj).get('return')
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return self._create_access_path(o)
|
return self._create_access_path(o)
|
||||||
|
|
||||||
|
|||||||
@@ -323,8 +323,7 @@ class ModuleContext(TreeContextMixin, ValueContext):
|
|||||||
),
|
),
|
||||||
self.get_global_filter(),
|
self.get_global_filter(),
|
||||||
)
|
)
|
||||||
for f in filters: # Python 2...
|
yield from filters
|
||||||
yield f
|
|
||||||
|
|
||||||
def get_global_filter(self):
|
def get_global_filter(self):
|
||||||
return GlobalNameFilter(self, self.tree_node)
|
return GlobalNameFilter(self, self.tree_node)
|
||||||
|
|||||||
@@ -166,9 +166,9 @@ class _FunctionExecutionFilter(ParserTreeFilter):
|
|||||||
|
|
||||||
|
|
||||||
class FunctionExecutionFilter(_FunctionExecutionFilter):
|
class FunctionExecutionFilter(_FunctionExecutionFilter):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, arguments, **kwargs):
|
||||||
self._arguments = kwargs.pop('arguments') # Python 2
|
|
||||||
super(FunctionExecutionFilter, self).__init__(*args, **kwargs)
|
super(FunctionExecutionFilter, self).__init__(*args, **kwargs)
|
||||||
|
self._arguments = arguments
|
||||||
|
|
||||||
def _convert_param(self, param, name):
|
def _convert_param(self, param, name):
|
||||||
return ParamName(self._function_value, name, self._arguments)
|
return ParamName(self._function_value, name, self._arguments)
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ def _load_from_typeshed(inference_state, python_value_set, parent_module_value,
|
|||||||
def _try_to_load_stub_from_file(inference_state, python_value_set, file_io, import_names):
|
def _try_to_load_stub_from_file(inference_state, python_value_set, file_io, import_names):
|
||||||
try:
|
try:
|
||||||
stub_module_node = parse_stub_module(inference_state, file_io)
|
stub_module_node = parse_stub_module(inference_state, file_io)
|
||||||
except (OSError, IOError): # IOError is Python 2 only
|
except OSError: # IOError is Python 2 only
|
||||||
# The file that you're looking for doesn't exist (anymore).
|
# The file that you're looking for doesn't exist (anymore).
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -88,12 +88,10 @@ class TypingModuleName(NameWrapper):
|
|||||||
inference_state, self.parent_context, self.tree_name)
|
inference_state, self.parent_context, self.tree_name)
|
||||||
elif name in ('no_type_check', 'no_type_check_decorator'):
|
elif name in ('no_type_check', 'no_type_check_decorator'):
|
||||||
# This is not necessary, as long as we are not doing type checking.
|
# This is not necessary, as long as we are not doing type checking.
|
||||||
for c in self._wrapped_name.infer(): # Fuck my life Python 2
|
yield from self._wrapped_name.infer()
|
||||||
yield c
|
|
||||||
else:
|
else:
|
||||||
# Everything else shouldn't be relevant for type checking.
|
# Everything else shouldn't be relevant for type checking.
|
||||||
for c in self._wrapped_name.infer(): # Fuck my life Python 2
|
yield from self._wrapped_name.infer()
|
||||||
yield c
|
|
||||||
|
|
||||||
|
|
||||||
class TypingModuleFilterWrapper(FilterWrapper):
|
class TypingModuleFilterWrapper(FilterWrapper):
|
||||||
|
|||||||
@@ -272,9 +272,8 @@ def get_module_contexts_containing_name(inference_state, module_contexts, name,
|
|||||||
return
|
return
|
||||||
|
|
||||||
file_io_iterator = _find_python_files_in_sys_path(inference_state, module_contexts)
|
file_io_iterator = _find_python_files_in_sys_path(inference_state, module_contexts)
|
||||||
for x in search_in_file_ios(inference_state, file_io_iterator, name,
|
yield from search_in_file_ios(inference_state, file_io_iterator, name,
|
||||||
limit_reduction=limit_reduction):
|
limit_reduction=limit_reduction)
|
||||||
yield x # Python 2...
|
|
||||||
|
|
||||||
|
|
||||||
def search_in_file_ios(inference_state, file_io_iterator, name, limit_reduction=1):
|
def search_in_file_ios(inference_state, file_io_iterator, name, limit_reduction=1):
|
||||||
|
|||||||
@@ -224,9 +224,7 @@ def _infer_node(context, element):
|
|||||||
| context.infer_node(element.children[-1]))
|
| context.infer_node(element.children[-1]))
|
||||||
elif typ == 'operator':
|
elif typ == 'operator':
|
||||||
# Must be an ellipsis, other operators are not inferred.
|
# Must be an ellipsis, other operators are not inferred.
|
||||||
# In Python 2 ellipsis is coded as three single dot tokens, not
|
if element.value != '...':
|
||||||
# as one token 3 dot token.
|
|
||||||
if element.value not in ('.', '...'):
|
|
||||||
origin = element.parent
|
origin = element.parent
|
||||||
raise AssertionError("unhandled operator %s in %s " % (repr(element.value), origin))
|
raise AssertionError("unhandled operator %s in %s " % (repr(element.value), origin))
|
||||||
return ValueSet([compiled.builtin_from_name(inference_state, u'Ellipsis')])
|
return ValueSet([compiled.builtin_from_name(inference_state, u'Ellipsis')])
|
||||||
@@ -288,10 +286,6 @@ def infer_atom(context, atom):
|
|||||||
"""
|
"""
|
||||||
state = context.inference_state
|
state = context.inference_state
|
||||||
if atom.type == 'name':
|
if atom.type == 'name':
|
||||||
if atom.value in ('True', 'False', 'None'):
|
|
||||||
# Python 2...
|
|
||||||
return ValueSet([compiled.builtin_from_name(state, atom.value)])
|
|
||||||
|
|
||||||
# This is the first global lookup.
|
# This is the first global lookup.
|
||||||
stmt = tree.search_ancestor(
|
stmt = tree.search_ancestor(
|
||||||
atom, 'expr_stmt', 'lambdef'
|
atom, 'expr_stmt', 'lambdef'
|
||||||
@@ -857,8 +851,7 @@ def _infer_subscript_list(context, index):
|
|||||||
return ValueSet([iterable.Slice(context, None, None, None)])
|
return ValueSet([iterable.Slice(context, None, None, None)])
|
||||||
|
|
||||||
elif index.type == 'subscript' and not index.children[0] == '.':
|
elif index.type == 'subscript' and not index.children[0] == '.':
|
||||||
# subscript basically implies a slice operation, except for Python 2's
|
# subscript basically implies a slice operation
|
||||||
# Ellipsis.
|
|
||||||
# e.g. array[:3]
|
# e.g. array[:3]
|
||||||
result = []
|
result = []
|
||||||
for el in index.children:
|
for el in index.children:
|
||||||
|
|||||||
@@ -89,10 +89,6 @@ class PushBackIterator(object):
|
|||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def next(self):
|
|
||||||
""" Python 2 Compatibility """
|
|
||||||
return self.__next__()
|
|
||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
if self.pushes:
|
if self.pushes:
|
||||||
self.current = self.pushes.pop()
|
self.current = self.pushes.pop()
|
||||||
|
|||||||
@@ -191,13 +191,11 @@ class ClassMixin(object):
|
|||||||
if include_metaclasses:
|
if include_metaclasses:
|
||||||
metaclasses = self.get_metaclasses()
|
metaclasses = self.get_metaclasses()
|
||||||
if metaclasses:
|
if metaclasses:
|
||||||
for f in self.get_metaclass_filters(metaclasses, is_instance):
|
yield from self.get_metaclass_filters(metaclasses, is_instance)
|
||||||
yield f # Python 2..
|
|
||||||
|
|
||||||
for cls in self.py__mro__():
|
for cls in self.py__mro__():
|
||||||
if cls.is_compiled():
|
if cls.is_compiled():
|
||||||
for filter in cls.get_filters(is_instance=is_instance):
|
yield from cls.get_filters(is_instance=is_instance)
|
||||||
yield filter
|
|
||||||
else:
|
else:
|
||||||
yield ClassFilter(
|
yield ClassFilter(
|
||||||
self, node_context=cls.as_context(),
|
self, node_context=cls.as_context(),
|
||||||
|
|||||||
Reference in New Issue
Block a user