From 7f673242107efa2b15030c06239cc901935858dd Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 2 Jul 2020 10:30:58 +0200 Subject: [PATCH] Remove a lot more Python 2 mentions and todos --- jedi/inference/compiled/access.py | 11 +++-------- jedi/inference/context.py | 3 +-- jedi/inference/filters.py | 4 ++-- jedi/inference/gradual/typeshed.py | 2 +- jedi/inference/gradual/typing.py | 6 ++---- jedi/inference/references.py | 5 ++--- jedi/inference/syntax_tree.py | 11 ++--------- jedi/inference/utils.py | 4 ---- jedi/inference/value/klass.py | 6 ++---- 9 files changed, 15 insertions(+), 37 deletions(-) diff --git a/jedi/inference/compiled/access.py b/jedi/inference/compiled/access.py index 1482cabb..5702f74a 100644 --- a/jedi/inference/compiled/access.py +++ b/jedi/inference/compiled/access.py @@ -6,6 +6,7 @@ from collections import namedtuple import warnings import re import builtins +import typing from jedi.inference.compiled.getattr_static import getattr_static @@ -504,15 +505,9 @@ class DirectObjectAccess(object): return None try: - # Python 2 doesn't have typing. - import typing - except ImportError: + o = typing.get_type_hints(self._obj).get('return') + except Exception: pass - else: - try: - o = typing.get_type_hints(self._obj).get('return') - except Exception: - pass return self._create_access_path(o) diff --git a/jedi/inference/context.py b/jedi/inference/context.py index 0915911a..e1074be9 100644 --- a/jedi/inference/context.py +++ b/jedi/inference/context.py @@ -323,8 +323,7 @@ class ModuleContext(TreeContextMixin, ValueContext): ), self.get_global_filter(), ) - for f in filters: # Python 2... - yield f + yield from filters def get_global_filter(self): return GlobalNameFilter(self, self.tree_node) diff --git a/jedi/inference/filters.py b/jedi/inference/filters.py index 25d63e67..79572921 100644 --- a/jedi/inference/filters.py +++ b/jedi/inference/filters.py @@ -166,9 +166,9 @@ class _FunctionExecutionFilter(ParserTreeFilter): class FunctionExecutionFilter(_FunctionExecutionFilter): - def __init__(self, *args, **kwargs): - self._arguments = kwargs.pop('arguments') # Python 2 + def __init__(self, *args, arguments, **kwargs): super(FunctionExecutionFilter, self).__init__(*args, **kwargs) + self._arguments = arguments def _convert_param(self, param, name): return ParamName(self._function_value, name, self._arguments) diff --git a/jedi/inference/gradual/typeshed.py b/jedi/inference/gradual/typeshed.py index 79ea4416..4f330f62 100644 --- a/jedi/inference/gradual/typeshed.py +++ b/jedi/inference/gradual/typeshed.py @@ -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): try: 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). return None else: diff --git a/jedi/inference/gradual/typing.py b/jedi/inference/gradual/typing.py index 2d8a0cb0..736beaf6 100644 --- a/jedi/inference/gradual/typing.py +++ b/jedi/inference/gradual/typing.py @@ -88,12 +88,10 @@ class TypingModuleName(NameWrapper): inference_state, self.parent_context, self.tree_name) elif name in ('no_type_check', 'no_type_check_decorator'): # 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 c + yield from self._wrapped_name.infer() else: # Everything else shouldn't be relevant for type checking. - for c in self._wrapped_name.infer(): # Fuck my life Python 2 - yield c + yield from self._wrapped_name.infer() class TypingModuleFilterWrapper(FilterWrapper): diff --git a/jedi/inference/references.py b/jedi/inference/references.py index 963a16d3..b729c2fd 100644 --- a/jedi/inference/references.py +++ b/jedi/inference/references.py @@ -272,9 +272,8 @@ def get_module_contexts_containing_name(inference_state, module_contexts, name, return 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, - limit_reduction=limit_reduction): - yield x # Python 2... + yield from search_in_file_ios(inference_state, file_io_iterator, name, + limit_reduction=limit_reduction) def search_in_file_ios(inference_state, file_io_iterator, name, limit_reduction=1): diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index a7565e41..7d16e439 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -224,9 +224,7 @@ def _infer_node(context, element): | context.infer_node(element.children[-1])) elif typ == 'operator': # Must be an ellipsis, other operators are not inferred. - # In Python 2 ellipsis is coded as three single dot tokens, not - # as one token 3 dot token. - if element.value not in ('.', '...'): + if element.value != '...': origin = element.parent raise AssertionError("unhandled operator %s in %s " % (repr(element.value), origin)) return ValueSet([compiled.builtin_from_name(inference_state, u'Ellipsis')]) @@ -288,10 +286,6 @@ def infer_atom(context, atom): """ state = context.inference_state 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. stmt = tree.search_ancestor( atom, 'expr_stmt', 'lambdef' @@ -857,8 +851,7 @@ def _infer_subscript_list(context, index): return ValueSet([iterable.Slice(context, None, None, None)]) elif index.type == 'subscript' and not index.children[0] == '.': - # subscript basically implies a slice operation, except for Python 2's - # Ellipsis. + # subscript basically implies a slice operation # e.g. array[:3] result = [] for el in index.children: diff --git a/jedi/inference/utils.py b/jedi/inference/utils.py index 805aff1d..6aebd4c5 100644 --- a/jedi/inference/utils.py +++ b/jedi/inference/utils.py @@ -89,10 +89,6 @@ class PushBackIterator(object): def __iter__(self): return self - def next(self): - """ Python 2 Compatibility """ - return self.__next__() - def __next__(self): if self.pushes: self.current = self.pushes.pop() diff --git a/jedi/inference/value/klass.py b/jedi/inference/value/klass.py index 76117fdd..282ce0d5 100644 --- a/jedi/inference/value/klass.py +++ b/jedi/inference/value/klass.py @@ -191,13 +191,11 @@ class ClassMixin(object): if include_metaclasses: metaclasses = self.get_metaclasses() if metaclasses: - for f in self.get_metaclass_filters(metaclasses, is_instance): - yield f # Python 2.. + yield from self.get_metaclass_filters(metaclasses, is_instance) for cls in self.py__mro__(): if cls.is_compiled(): - for filter in cls.get_filters(is_instance=is_instance): - yield filter + yield from cls.get_filters(is_instance=is_instance) else: yield ClassFilter( self, node_context=cls.as_context(),