forked from VimPlug/jedi
Get rid of a lot of flake8 errors
This commit is contained in:
@@ -39,7 +39,9 @@ def imitate_pydoc(string):
|
|||||||
string = h.symbols[string]
|
string = h.symbols[string]
|
||||||
string, _, related = string.partition(' ')
|
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):
|
while isinstance(string, str):
|
||||||
string = get_target(string)
|
string = get_target(string)
|
||||||
|
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ class Error(object):
|
|||||||
return self.__unicode__()
|
return self.__unicode__()
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return (self.path == other.path and self.name == other.name and
|
return (self.path == other.path and self.name == other.name
|
||||||
self._start_pos == other._start_pos)
|
and self._start_pos == other._start_pos)
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
return not self.__eq__(other)
|
return not self.__eq__(other)
|
||||||
@@ -114,7 +114,6 @@ def _check_for_setattr(instance):
|
|||||||
|
|
||||||
def add_attribute_error(name_context, lookup_value, name):
|
def add_attribute_error(name_context, lookup_value, name):
|
||||||
message = ('AttributeError: %s has no attribute %s.' % (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
|
# Check for __getattr__/__getattribute__ existance and issue a warning
|
||||||
# instead of an error, if that happens.
|
# instead of an error, if that happens.
|
||||||
typ = Error
|
typ = Error
|
||||||
@@ -150,7 +149,7 @@ def _check_for_exception_catch(node_context, jedi_name, exception, payload=None)
|
|||||||
# Only nodes in try
|
# Only nodes in try
|
||||||
iterator = iter(obj.children)
|
iterator = iter(obj.children)
|
||||||
for branch_type in iterator:
|
for branch_type in iterator:
|
||||||
colon = next(iterator)
|
next(iterator) # The colon
|
||||||
suite = next(iterator)
|
suite = next(iterator)
|
||||||
if branch_type == 'try' \
|
if branch_type == 'try' \
|
||||||
and not (branch_type.start_pos < jedi_name.start_pos <= suite.end_pos):
|
and not (branch_type.start_pos < jedi_name.start_pos <= suite.end_pos):
|
||||||
|
|||||||
@@ -161,8 +161,7 @@ def unpack_arglist(arglist):
|
|||||||
# definitions.
|
# definitions.
|
||||||
if not (arglist.type in ('arglist', 'testlist') or (
|
if not (arglist.type in ('arglist', 'testlist') or (
|
||||||
# in python 3.5 **arg is an argument, not arglist
|
# in python 3.5 **arg is an argument, not arglist
|
||||||
(arglist.type == 'argument') and
|
arglist.type == 'argument' and arglist.children[0] in ('*', '**'))):
|
||||||
arglist.children[0] in ('*', '**'))):
|
|
||||||
yield 0, arglist
|
yield 0, arglist
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ _NO_DEFAULT = object()
|
|||||||
_RECURSION_SENTINEL = 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:
|
""" This is a typical memoization decorator, BUT there is one difference:
|
||||||
To prevent recursion it sets defaults.
|
To prevent recursion it sets defaults.
|
||||||
|
|
||||||
|
|||||||
@@ -46,9 +46,9 @@ def _shadowed_dict_newstyle(klass):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if not (type(class_dict) is types.GetSetDescriptorType and
|
if not (type(class_dict) is types.GetSetDescriptorType
|
||||||
class_dict.__name__ == "__dict__" and
|
and class_dict.__name__ == "__dict__"
|
||||||
class_dict.__objclass__ is entry):
|
and class_dict.__objclass__ is entry):
|
||||||
return class_dict
|
return class_dict
|
||||||
return _sentinel
|
return _sentinel
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ from jedi.inference.helpers import SimpleGetItemNotFound
|
|||||||
from jedi.inference.value import ModuleValue
|
from jedi.inference.value import ModuleValue
|
||||||
from jedi.inference.cache import inference_state_function_cache, \
|
from jedi.inference.cache import inference_state_function_cache, \
|
||||||
inference_state_method_cache
|
inference_state_method_cache
|
||||||
from jedi.inference.compiled.getattr_static import getattr_static
|
|
||||||
from jedi.inference.compiled.access import compiled_objects_cache, \
|
from jedi.inference.compiled.access import compiled_objects_cache, \
|
||||||
ALLOWED_GETITEM_TYPES, get_api_type
|
ALLOWED_GETITEM_TYPES, get_api_type
|
||||||
from jedi.inference.compiled.value import create_cached_compiled_object
|
from jedi.inference.compiled.value import create_cached_compiled_object
|
||||||
@@ -63,7 +62,7 @@ class MixedObject(ValueWrapper):
|
|||||||
def py__call__(self, arguments):
|
def py__call__(self, arguments):
|
||||||
# Fallback to the wrapped value if to stub returns no values.
|
# Fallback to the wrapped value if to stub returns no values.
|
||||||
values = to_stub(self._wrapped_value)
|
values = to_stub(self._wrapped_value)
|
||||||
if not values:# or self in values:
|
if not values:
|
||||||
values = self._wrapped_value
|
values = self._wrapped_value
|
||||||
return values.py__call__(arguments)
|
return values.py__call__(arguments)
|
||||||
|
|
||||||
@@ -173,13 +172,13 @@ def _get_object_to_check(python_object):
|
|||||||
# Can return a ValueError when it wraps around
|
# Can return a ValueError when it wraps around
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if (inspect.ismodule(python_object) or
|
if (inspect.ismodule(python_object)
|
||||||
inspect.isclass(python_object) or
|
or inspect.isclass(python_object)
|
||||||
inspect.ismethod(python_object) or
|
or inspect.ismethod(python_object)
|
||||||
inspect.isfunction(python_object) or
|
or inspect.isfunction(python_object)
|
||||||
inspect.istraceback(python_object) or
|
or inspect.istraceback(python_object)
|
||||||
inspect.isframe(python_object) or
|
or inspect.isframe(python_object)
|
||||||
inspect.iscode(python_object)):
|
or inspect.iscode(python_object)):
|
||||||
return python_object
|
return python_object
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -399,8 +399,4 @@ class AccessHandle(object):
|
|||||||
|
|
||||||
@memoize_method
|
@memoize_method
|
||||||
def _cached_results(self, name, *args, **kwargs):
|
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)
|
return self._subprocess.get_compiled_method_return(self.id, name, *args, **kwargs)
|
||||||
|
|||||||
@@ -50,7 +50,10 @@ class CompiledObject(Value):
|
|||||||
return_annotation = self.access_handle.get_return_annotation()
|
return_annotation = self.access_handle.get_return_annotation()
|
||||||
if return_annotation is not None:
|
if return_annotation is not None:
|
||||||
# TODO the return annotation may also be a string.
|
# 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:
|
try:
|
||||||
self.access_handle.getattr_paths(u'__call__')
|
self.access_handle.getattr_paths(u'__call__')
|
||||||
@@ -411,10 +414,11 @@ class CompiledObjectFilter(AbstractFilter):
|
|||||||
self.is_instance = is_instance
|
self.is_instance = is_instance
|
||||||
|
|
||||||
def get(self, name):
|
def get(self, name):
|
||||||
|
access_handle = self.compiled_object.access_handle
|
||||||
return self._get(
|
return self._get(
|
||||||
name,
|
name,
|
||||||
lambda name, unsafe: self.compiled_object.access_handle.is_allowed_getattr(name, unsafe),
|
lambda name, unsafe: access_handle.is_allowed_getattr(name, unsafe),
|
||||||
lambda name: name in self.compiled_object.access_handle.dir(),
|
lambda name: name in access_handle.dir(),
|
||||||
check_has_attribute=True
|
check_has_attribute=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ class ModuleCache(object):
|
|||||||
self._name_cache = {}
|
self._name_cache = {}
|
||||||
|
|
||||||
def add(self, string_names, value_set):
|
def add(self, string_names, value_set):
|
||||||
#path = module.py__file__()
|
|
||||||
#self._path_cache[path] = value_set
|
|
||||||
if string_names is not None:
|
if string_names is not None:
|
||||||
self._name_cache[string_names] = value_set
|
self._name_cache[string_names] = value_set
|
||||||
|
|
||||||
@@ -302,8 +300,10 @@ class Importer(object):
|
|||||||
names = []
|
names = []
|
||||||
# add builtin module names
|
# add builtin module names
|
||||||
if search_path is None and in_module is None:
|
if search_path is None and in_module is None:
|
||||||
names += [ImportName(self._module_context, name)
|
names += [
|
||||||
for name in self._inference_state.compiled_subprocess.get_builtin_module_names()]
|
ImportName(self._module_context, name)
|
||||||
|
for name in self._inference_state.compiled_subprocess.get_builtin_module_names()
|
||||||
|
]
|
||||||
|
|
||||||
if search_path is None:
|
if search_path is None:
|
||||||
search_path = self._sys_path_with_modifications(is_completion=True)
|
search_path = self._sys_path_with_modifications(is_completion=True)
|
||||||
|
|||||||
@@ -177,8 +177,8 @@ def get_executed_param_names_and_issues(function_value, arguments):
|
|||||||
for k in set(param_dict) - set(keys_used):
|
for k in set(param_dict) - set(keys_used):
|
||||||
param = param_dict[k]
|
param = param_dict[k]
|
||||||
|
|
||||||
if not (non_matching_keys or had_multiple_value_error or
|
if not (non_matching_keys or had_multiple_value_error
|
||||||
param.star_count or param.default):
|
or param.star_count or param.default):
|
||||||
# add a warning only if there's not another one.
|
# add a warning only if there's not another one.
|
||||||
for contextualized_node in arguments.get_calling_nodes():
|
for contextualized_node in arguments.get_calling_nodes():
|
||||||
m = _error_argument_count(funcdef, len(unpacked_va))
|
m = _error_argument_count(funcdef, len(unpacked_va))
|
||||||
|
|||||||
@@ -212,8 +212,8 @@ def _infer_node(context, element):
|
|||||||
return value_set
|
return value_set
|
||||||
elif typ == 'test':
|
elif typ == 'test':
|
||||||
# `x if foo else y` case.
|
# `x if foo else y` case.
|
||||||
return (context.infer_node(element.children[0]) |
|
return (context.infer_node(element.children[0])
|
||||||
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
|
# In Python 2 ellipsis is coded as three single dot tokens, not
|
||||||
@@ -328,8 +328,8 @@ def infer_atom(context, atom):
|
|||||||
c = atom.children
|
c = atom.children
|
||||||
# Parentheses without commas are not tuples.
|
# Parentheses without commas are not tuples.
|
||||||
if c[0] == '(' and not len(c) == 2 \
|
if c[0] == '(' and not len(c) == 2 \
|
||||||
and not(c[1].type == 'testlist_comp' and
|
and not(c[1].type == 'testlist_comp'
|
||||||
len(c[1].children) > 1):
|
and len(c[1].children) > 1):
|
||||||
return context.infer_node(c[1])
|
return context.infer_node(c[1])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -355,8 +355,8 @@ def infer_atom(context, atom):
|
|||||||
array_node_c = array_node.children
|
array_node_c = array_node.children
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
array_node_c = []
|
array_node_c = []
|
||||||
if c[0] == '{' and (array_node == '}' or ':' in array_node_c or
|
if c[0] == '{' and (array_node == '}' or ':' in array_node_c
|
||||||
'**' in array_node_c):
|
or '**' in array_node_c):
|
||||||
new_value = iterable.DictLiteralValue(state, context, atom)
|
new_value = iterable.DictLiteralValue(state, context, atom)
|
||||||
else:
|
else:
|
||||||
new_value = iterable.SequenceLiteralValue(state, context, atom)
|
new_value = iterable.SequenceLiteralValue(state, context, atom)
|
||||||
|
|||||||
@@ -146,8 +146,8 @@ def extract(script, new_name):
|
|||||||
# add parentheses in multi-line case
|
# add parentheses in multi-line case
|
||||||
open_brackets = ['(', '[', '{']
|
open_brackets = ['(', '[', '{']
|
||||||
close_brackets = [')', ']', '}']
|
close_brackets = [')', ']', '}']
|
||||||
if '\n' in text and not (text[0] in open_brackets and text[-1] ==
|
if '\n' in text and not (text[0] in open_brackets and text[-1]
|
||||||
close_brackets[open_brackets.index(text[0])]):
|
== close_brackets[open_brackets.index(text[0])]):
|
||||||
text = '(%s)' % text
|
text = '(%s)' % text
|
||||||
|
|
||||||
# add new line before statement
|
# 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 = line[expression_list[0].start_pos[1]:stmt.end_pos[1] + 1]
|
||||||
replace_str = replace_str.strip()
|
replace_str = replace_str.strip()
|
||||||
# tuples need parentheses
|
# 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]
|
arr = expression_list[0]
|
||||||
if replace_str[0] not in ['(', '[', '{'] and len(arr) > 1:
|
if replace_str[0] not in ['(', '[', '{'] and len(arr) > 1:
|
||||||
replace_str = '(%s)' % replace_str
|
replace_str = '(%s)' % replace_str
|
||||||
|
|||||||
Reference in New Issue
Block a user