forked from VimPlug/jedi
Fix some more issues with imports and attribute warnings of static analysis.
This commit is contained in:
@@ -79,7 +79,7 @@ class Warning(Error):
|
|||||||
|
|
||||||
def add(context, error_name, node, message=None, typ=Error, payload=None):
|
def add(context, error_name, node, message=None, typ=Error, payload=None):
|
||||||
from jedi.evaluate import Evaluator
|
from jedi.evaluate import Evaluator
|
||||||
if isinstance(context, Evaluator):
|
if isinstance(context, Evaluator) or context is None:
|
||||||
raise 1
|
raise 1
|
||||||
exception = CODES[error_name][1]
|
exception = CODES[error_name][1]
|
||||||
if _check_for_exception_catch(context, node, exception, payload):
|
if _check_for_exception_catch(context, node, exception, payload):
|
||||||
@@ -100,12 +100,13 @@ def _check_for_setattr(instance):
|
|||||||
if not isinstance(module, ModuleContext):
|
if not isinstance(module, ModuleContext):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
node = module.module_node
|
||||||
try:
|
try:
|
||||||
stmts = module.module_node.used_names['setattr']
|
stmts = node.used_names['setattr']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return any(instance.start_pos < stmt.start_pos < instance.end_pos
|
return any(node.start_pos < stmt.start_pos < node.end_pos
|
||||||
for stmt in stmts)
|
for stmt in stmts)
|
||||||
|
|
||||||
|
|
||||||
@@ -165,9 +166,10 @@ def _check_for_exception_catch(context, jedi_name, exception, payload=None):
|
|||||||
if isinstance(cls, iterable.AbstractSequence) and \
|
if isinstance(cls, iterable.AbstractSequence) and \
|
||||||
cls.array_type == 'tuple':
|
cls.array_type == 'tuple':
|
||||||
# multiple exceptions
|
# multiple exceptions
|
||||||
for typ in unite(cls.py__iter__()):
|
for lazy_context in cls.py__iter__():
|
||||||
if check_match(typ, exception):
|
for typ in lazy_context.infer():
|
||||||
return True
|
if check_match(typ, exception):
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
if check_match(cls, exception):
|
if check_match(cls, exception):
|
||||||
return True
|
return True
|
||||||
@@ -182,22 +184,20 @@ def _check_for_exception_catch(context, jedi_name, exception, payload=None):
|
|||||||
assert trailer.type == 'trailer'
|
assert trailer.type == 'trailer'
|
||||||
arglist = trailer.children[1]
|
arglist = trailer.children[1]
|
||||||
assert arglist.type == 'arglist'
|
assert arglist.type == 'arglist'
|
||||||
from jedi.evaluate.param import Arguments
|
from jedi.evaluate.param import TreeArguments
|
||||||
args = list(Arguments(context, arglist).unpack())
|
args = list(TreeArguments(context.evaluator, context, arglist).unpack())
|
||||||
# Arguments should be very simple
|
# Arguments should be very simple
|
||||||
assert len(args) == 2
|
assert len(args) == 2
|
||||||
|
|
||||||
# Check name
|
# Check name
|
||||||
key, values = args[1]
|
key, lazy_context = args[1]
|
||||||
assert len(values) == 1
|
names = list(lazy_context.infer())
|
||||||
names = list(context.eval_node(values[0]))
|
|
||||||
assert len(names) == 1 and isinstance(names[0], CompiledObject)
|
assert len(names) == 1 and isinstance(names[0], CompiledObject)
|
||||||
assert names[0].obj == str(payload[1])
|
assert names[0].obj == str(payload[1])
|
||||||
|
|
||||||
# Check objects
|
# Check objects
|
||||||
key, values = args[0]
|
key, lazy_context = args[0]
|
||||||
assert len(values) == 1
|
objects = lazy_context.infer()
|
||||||
objects = context.eval_node(values[0])
|
|
||||||
return payload[0] in objects
|
return payload[0] in objects
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ def search_params(evaluator, parent_context, funcdef):
|
|||||||
funcdef
|
funcdef
|
||||||
)
|
)
|
||||||
if function_executions:
|
if function_executions:
|
||||||
zipped_params = zip(*(
|
zipped_params = zip(*list(
|
||||||
function_execution.get_params()
|
function_execution.get_params()
|
||||||
for function_execution in function_executions
|
for function_execution in function_executions
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -357,7 +357,7 @@ class Importer(object):
|
|||||||
sys.path = temp
|
sys.path = temp
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# The module is not a package.
|
# The module is not a package.
|
||||||
_add_error(parent_module, import_path[-1])
|
_add_error(self.module_context, import_path[-1])
|
||||||
return set()
|
return set()
|
||||||
|
|
||||||
source = None
|
source = None
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class SpecialMethodFilter(DictFilter):
|
|||||||
# We can take the first index, because on builtin methods there's
|
# We can take the first index, because on builtin methods there's
|
||||||
# always only going to be one name. The same is true for the
|
# always only going to be one name. The same is true for the
|
||||||
# inferred values.
|
# inferred values.
|
||||||
builtin_func = filter.get(self.string_name)[0].infer().pop()
|
builtin_func = next(iter(filter.get(self.string_name)[0].infer()))
|
||||||
return set([BuiltinMethod(self.parent_context, self._callable, builtin_func)])
|
return set([BuiltinMethod(self.parent_context, self._callable, builtin_func)])
|
||||||
|
|
||||||
def __init__(self, context, dct, builtin_context):
|
def __init__(self, context, dct, builtin_context):
|
||||||
|
|||||||
Reference in New Issue
Block a user