diff --git a/jedi/api/keywords.py b/jedi/api/keywords.py index 3d3d317d..a4da0f3d 100644 --- a/jedi/api/keywords.py +++ b/jedi/api/keywords.py @@ -39,7 +39,9 @@ def imitate_pydoc(string): string = h.symbols[string] string, _, related = string.partition(' ') - get_target = lambda s: h.topics.get(s, h.keywords.get(s)) + def get_target(s): + return h.topics.get(s, h.keywords.get(s)) + while isinstance(string, str): string = get_target(string) diff --git a/jedi/inference/analysis.py b/jedi/inference/analysis.py index 48e7017f..9ce56370 100644 --- a/jedi/inference/analysis.py +++ b/jedi/inference/analysis.py @@ -58,8 +58,8 @@ class Error(object): return self.__unicode__() def __eq__(self, other): - return (self.path == other.path and self.name == other.name and - self._start_pos == other._start_pos) + return (self.path == other.path and self.name == other.name + and self._start_pos == other._start_pos) def __ne__(self, other): return not self.__eq__(other) @@ -114,7 +114,6 @@ def _check_for_setattr(instance): def add_attribute_error(name_context, lookup_value, name): message = ('AttributeError: %s has no attribute %s.' % (lookup_value, name)) - from jedi.inference.value.instance import CompiledInstanceName # Check for __getattr__/__getattribute__ existance and issue a warning # instead of an error, if that happens. typ = Error @@ -150,7 +149,7 @@ def _check_for_exception_catch(node_context, jedi_name, exception, payload=None) # Only nodes in try iterator = iter(obj.children) for branch_type in iterator: - colon = next(iterator) + next(iterator) # The colon suite = next(iterator) if branch_type == 'try' \ and not (branch_type.start_pos < jedi_name.start_pos <= suite.end_pos): diff --git a/jedi/inference/arguments.py b/jedi/inference/arguments.py index f4cda625..d7edeb4f 100644 --- a/jedi/inference/arguments.py +++ b/jedi/inference/arguments.py @@ -161,8 +161,7 @@ def unpack_arglist(arglist): # definitions. if not (arglist.type in ('arglist', 'testlist') or ( # in python 3.5 **arg is an argument, not arglist - (arglist.type == 'argument') and - arglist.children[0] in ('*', '**'))): + arglist.type == 'argument' and arglist.children[0] in ('*', '**'))): yield 0, arglist return diff --git a/jedi/inference/cache.py b/jedi/inference/cache.py index 839726ac..bbb9a32b 100644 --- a/jedi/inference/cache.py +++ b/jedi/inference/cache.py @@ -10,7 +10,8 @@ _NO_DEFAULT = object() _RECURSION_SENTINEL = object() -def _memoize_default(default=_NO_DEFAULT, inference_state_is_first_arg=False, second_arg_is_inference_state=False): +def _memoize_default(default=_NO_DEFAULT, inference_state_is_first_arg=False, + second_arg_is_inference_state=False): """ This is a typical memoization decorator, BUT there is one difference: To prevent recursion it sets defaults. diff --git a/jedi/inference/compiled/getattr_static.py b/jedi/inference/compiled/getattr_static.py index 946ac09b..b86a46f4 100644 --- a/jedi/inference/compiled/getattr_static.py +++ b/jedi/inference/compiled/getattr_static.py @@ -46,9 +46,9 @@ def _shadowed_dict_newstyle(klass): except KeyError: pass else: - if not (type(class_dict) is types.GetSetDescriptorType and - class_dict.__name__ == "__dict__" and - class_dict.__objclass__ is entry): + if not (type(class_dict) is types.GetSetDescriptorType + and class_dict.__name__ == "__dict__" + and class_dict.__objclass__ is entry): return class_dict return _sentinel diff --git a/jedi/inference/compiled/mixed.py b/jedi/inference/compiled/mixed.py index 8152c78a..87161b84 100644 --- a/jedi/inference/compiled/mixed.py +++ b/jedi/inference/compiled/mixed.py @@ -18,7 +18,6 @@ from jedi.inference.helpers import SimpleGetItemNotFound from jedi.inference.value import ModuleValue from jedi.inference.cache import inference_state_function_cache, \ inference_state_method_cache -from jedi.inference.compiled.getattr_static import getattr_static from jedi.inference.compiled.access import compiled_objects_cache, \ ALLOWED_GETITEM_TYPES, get_api_type from jedi.inference.compiled.value import create_cached_compiled_object @@ -63,7 +62,7 @@ class MixedObject(ValueWrapper): def py__call__(self, arguments): # Fallback to the wrapped value if to stub returns no values. values = to_stub(self._wrapped_value) - if not values:# or self in values: + if not values: values = self._wrapped_value return values.py__call__(arguments) @@ -160,7 +159,7 @@ def _load_module(inference_state, path): ).get_root_node() # python_module = inspect.getmodule(python_object) # TODO we should actually make something like this possible. - #inference_state.modules[python_module.__name__] = module_node + # inference_state.modules[python_module.__name__] = module_node return module_node @@ -173,13 +172,13 @@ def _get_object_to_check(python_object): # Can return a ValueError when it wraps around pass - if (inspect.ismodule(python_object) or - inspect.isclass(python_object) or - inspect.ismethod(python_object) or - inspect.isfunction(python_object) or - inspect.istraceback(python_object) or - inspect.isframe(python_object) or - inspect.iscode(python_object)): + if (inspect.ismodule(python_object) + or inspect.isclass(python_object) + or inspect.ismethod(python_object) + or inspect.isfunction(python_object) + or inspect.istraceback(python_object) + or inspect.isframe(python_object) + or inspect.iscode(python_object)): return python_object try: diff --git a/jedi/inference/compiled/subprocess/__init__.py b/jedi/inference/compiled/subprocess/__init__.py index bd7c801b..bad1803c 100644 --- a/jedi/inference/compiled/subprocess/__init__.py +++ b/jedi/inference/compiled/subprocess/__init__.py @@ -383,8 +383,8 @@ class AccessHandle(object): if name in ('id', 'access') or name.startswith('_'): raise AttributeError("Something went wrong with unpickling") - #if not is_py3: print >> sys.stderr, name - #print('getattr', name, file=sys.stderr) + # if not is_py3: print >> sys.stderr, name + # print('getattr', name, file=sys.stderr) return partial(self._workaround, force_unicode(name)) def _workaround(self, name, *args, **kwargs): @@ -399,8 +399,4 @@ class AccessHandle(object): @memoize_method def _cached_results(self, name, *args, **kwargs): - #if type(self._subprocess) == InferenceStateSubprocess: - #print(name, args, kwargs, - #self._subprocess.get_compiled_method_return(self.id, name, *args, **kwargs) - #) return self._subprocess.get_compiled_method_return(self.id, name, *args, **kwargs) diff --git a/jedi/inference/compiled/value.py b/jedi/inference/compiled/value.py index 10bba56c..b7d0085c 100644 --- a/jedi/inference/compiled/value.py +++ b/jedi/inference/compiled/value.py @@ -50,7 +50,10 @@ class CompiledObject(Value): return_annotation = self.access_handle.get_return_annotation() if return_annotation is not None: # TODO the return annotation may also be a string. - return create_from_access_path(self.inference_state, return_annotation).execute_annotation() + return create_from_access_path( + self.inference_state, + return_annotation + ).execute_annotation() try: self.access_handle.getattr_paths(u'__call__') @@ -411,10 +414,11 @@ class CompiledObjectFilter(AbstractFilter): self.is_instance = is_instance def get(self, name): + access_handle = self.compiled_object.access_handle return self._get( name, - lambda name, unsafe: self.compiled_object.access_handle.is_allowed_getattr(name, unsafe), - lambda name: name in self.compiled_object.access_handle.dir(), + lambda name, unsafe: access_handle.is_allowed_getattr(name, unsafe), + lambda name: name in access_handle.dir(), check_has_attribute=True ) diff --git a/jedi/inference/imports.py b/jedi/inference/imports.py index ab2c75bd..3ab68c67 100644 --- a/jedi/inference/imports.py +++ b/jedi/inference/imports.py @@ -42,8 +42,6 @@ class ModuleCache(object): self._name_cache = {} def add(self, string_names, value_set): - #path = module.py__file__() - #self._path_cache[path] = value_set if string_names is not None: self._name_cache[string_names] = value_set @@ -123,8 +121,8 @@ def _prepare_infer_import(module_context, tree_name): importer = Importer(module_context.inference_state, tuple(import_path), module_context, import_node.level) - #if import_node.is_nested() and not self.nested_resolve: - # scopes = [NestedImportModule(module, import_node)] + # if import_node.is_nested() and not self.nested_resolve: + # scopes = [NestedImportModule(module, import_node)] return from_import_name, tuple(import_path), import_node.level, importer.follow() @@ -302,8 +300,10 @@ class Importer(object): names = [] # add builtin module names if search_path is None and in_module is None: - names += [ImportName(self._module_context, name) - for name in self._inference_state.compiled_subprocess.get_builtin_module_names()] + names += [ + ImportName(self._module_context, name) + for name in self._inference_state.compiled_subprocess.get_builtin_module_names() + ] if search_path is None: search_path = self._sys_path_with_modifications(is_completion=True) diff --git a/jedi/inference/param.py b/jedi/inference/param.py index 6205fed1..27bd60a4 100644 --- a/jedi/inference/param.py +++ b/jedi/inference/param.py @@ -177,8 +177,8 @@ def get_executed_param_names_and_issues(function_value, arguments): for k in set(param_dict) - set(keys_used): param = param_dict[k] - if not (non_matching_keys or had_multiple_value_error or - param.star_count or param.default): + if not (non_matching_keys or had_multiple_value_error + or param.star_count or param.default): # add a warning only if there's not another one. for contextualized_node in arguments.get_calling_nodes(): m = _error_argument_count(funcdef, len(unpacked_va)) diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index 5e73878f..e58a4894 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -212,8 +212,8 @@ def _infer_node(context, element): return value_set elif typ == 'test': # `x if foo else y` case. - return (context.infer_node(element.children[0]) | - context.infer_node(element.children[-1])) + return (context.infer_node(element.children[0]) + | 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 @@ -328,8 +328,8 @@ def infer_atom(context, atom): c = atom.children # Parentheses without commas are not tuples. if c[0] == '(' and not len(c) == 2 \ - and not(c[1].type == 'testlist_comp' and - len(c[1].children) > 1): + and not(c[1].type == 'testlist_comp' + and len(c[1].children) > 1): return context.infer_node(c[1]) try: @@ -355,8 +355,8 @@ def infer_atom(context, atom): array_node_c = array_node.children except AttributeError: array_node_c = [] - if c[0] == '{' and (array_node == '}' or ':' in array_node_c or - '**' in array_node_c): + if c[0] == '{' and (array_node == '}' or ':' in array_node_c + or '**' in array_node_c): new_value = iterable.DictLiteralValue(state, context, atom) else: new_value = iterable.SequenceLiteralValue(state, context, atom) diff --git a/jedi/refactoring.py b/jedi/refactoring.py index 4a25ed66..df125bc6 100644 --- a/jedi/refactoring.py +++ b/jedi/refactoring.py @@ -146,8 +146,8 @@ def extract(script, new_name): # add parentheses in multi-line case open_brackets = ['(', '[', '{'] close_brackets = [')', ']', '}'] - if '\n' in text and not (text[0] in open_brackets and text[-1] == - close_brackets[open_brackets.index(text[0])]): + if '\n' in text and not (text[0] in open_brackets and text[-1] + == close_brackets[open_brackets.index(text[0])]): text = '(%s)' % text # add new line before statement @@ -183,7 +183,7 @@ def inline(script): replace_str = line[expression_list[0].start_pos[1]:stmt.end_pos[1] + 1] replace_str = replace_str.strip() # tuples need parentheses - if expression_list and isinstance(expression_list[0], pr.Array): + if expression_list and expression_list[0].type == 'TODO': arr = expression_list[0] if replace_str[0] not in ['(', '[', '{'] and len(arr) > 1: replace_str = '(%s)' % replace_str