mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 15:51:51 +08:00
Fix some static analysis tests like attribute errors and normal arguments.
This commit is contained in:
@@ -77,17 +77,16 @@ class Warning(Error):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def add(context, name, jedi_name, message=None, typ=Error, payload=None):
|
def add(context, error_name, node, message=None, typ=Error, payload=None):
|
||||||
return
|
|
||||||
from jedi.evaluate import Evaluator
|
from jedi.evaluate import Evaluator
|
||||||
if isinstance(context, Evaluator):
|
if isinstance(context, Evaluator):
|
||||||
raise 1
|
raise 1
|
||||||
exception = CODES[name][1]
|
exception = CODES[error_name][1]
|
||||||
if _check_for_exception_catch(context, jedi_name, exception, payload):
|
if _check_for_exception_catch(context, node, exception, payload):
|
||||||
return
|
return
|
||||||
|
|
||||||
module_path = jedi_name.get_root_node().path
|
module_path = node.get_root_node().path
|
||||||
instance = typ(name, module_path, jedi_name.start_pos, message)
|
instance = typ(error_name, module_path, node.start_pos, message)
|
||||||
debug.warning(str(instance), format=False)
|
debug.warning(str(instance), format=False)
|
||||||
context.evaluator.analysis.append(instance)
|
context.evaluator.analysis.append(instance)
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,14 @@ from jedi.evaluate import docstrings
|
|||||||
from jedi.evaluate import pep0484
|
from jedi.evaluate import pep0484
|
||||||
|
|
||||||
|
|
||||||
|
def add_argument_issue(parent_context, error_name, lazy_context, message):
|
||||||
|
if isinstance(lazy_context, context.LazyTreeContext):
|
||||||
|
node = lazy_context.data
|
||||||
|
if node.parent.type == 'argument':
|
||||||
|
node = node.parent
|
||||||
|
analysis.add(parent_context, error_name, node, message)
|
||||||
|
|
||||||
|
|
||||||
def try_iter_content(types, depth=0):
|
def try_iter_content(types, depth=0):
|
||||||
"""Helper method for static analysis."""
|
"""Helper method for static analysis."""
|
||||||
if depth > 10:
|
if depth > 10:
|
||||||
@@ -294,14 +302,14 @@ def get_params(evaluator, parent_context, func, var_args):
|
|||||||
# No value: Return an empty container
|
# No value: Return an empty container
|
||||||
if param.default is None:
|
if param.default is None:
|
||||||
result_arg = context.LazyUnknownContext()
|
result_arg = context.LazyUnknownContext()
|
||||||
|
if not keys_only:
|
||||||
|
calling_va = var_args.get_calling_var_args()
|
||||||
|
if calling_va is not None:
|
||||||
|
m = _error_argument_count(func, len(unpacked_va))
|
||||||
|
analysis.add(parent_context, 'type-error-too-few-arguments',
|
||||||
|
calling_va, message=m)
|
||||||
else:
|
else:
|
||||||
result_arg = context.LazyTreeContext(parent_context, param.default)
|
result_arg = context.LazyTreeContext(parent_context, param.default)
|
||||||
if not keys_only:
|
|
||||||
calling_va = var_args.get_calling_var_args()
|
|
||||||
if calling_va is not None:
|
|
||||||
m = _error_argument_count(func, len(unpacked_va))
|
|
||||||
analysis.add(parent_context, 'type-error-too-few-arguments',
|
|
||||||
calling_va, message=m)
|
|
||||||
else:
|
else:
|
||||||
result_arg = argument
|
result_arg = argument
|
||||||
|
|
||||||
@@ -324,36 +332,39 @@ def get_params(evaluator, parent_context, func, var_args):
|
|||||||
analysis.add(parent_context, 'type-error-too-few-arguments',
|
analysis.add(parent_context, 'type-error-too-few-arguments',
|
||||||
calling_va, message=m)
|
calling_va, message=m)
|
||||||
|
|
||||||
for key, argument in non_matching_keys.items():
|
for key, lazy_context in non_matching_keys.items():
|
||||||
m = "TypeError: %s() got an unexpected keyword argument '%s'." \
|
m = "TypeError: %s() got an unexpected keyword argument '%s'." \
|
||||||
% (func.name, key)
|
% (func.name, key)
|
||||||
analysis.add(parent_context, 'type-error-keyword-argument', argument.whatever, message=m)
|
add_argument_issue(
|
||||||
|
parent_context,
|
||||||
|
'type-error-keyword-argument',
|
||||||
|
lazy_context,
|
||||||
|
message=m
|
||||||
|
)
|
||||||
|
|
||||||
remaining_arguments = list(var_arg_iterator)
|
remaining_arguments = list(var_arg_iterator)
|
||||||
if remaining_arguments:
|
if remaining_arguments:
|
||||||
m = _error_argument_count(func, len(unpacked_va))
|
m = _error_argument_count(func, len(unpacked_va))
|
||||||
# Just report an error for the first param that is not needed (like
|
# Just report an error for the first param that is not needed (like
|
||||||
# cPython).
|
# cPython).
|
||||||
first_key, first_values = remaining_arguments[0]
|
first_key, lazy_context = remaining_arguments[0]
|
||||||
# TODO REENABLE
|
if first_key is not None:
|
||||||
for v in []:#first_values:
|
# Is a keyword argument, return the whole thing instead of just
|
||||||
if first_key is not None:
|
# the value node.
|
||||||
# Is a keyword argument, return the whole thing instead of just
|
try:
|
||||||
# the value node.
|
non_kw_param = keys_used[first_key]
|
||||||
v = v.parent
|
except KeyError:
|
||||||
try:
|
pass
|
||||||
non_kw_param = keys_used[first_key]
|
else:
|
||||||
except KeyError:
|
"""
|
||||||
pass
|
origin_args = non_kw_param.parent.var_args.argument_node
|
||||||
else:
|
# TODO calculate the var_args tree and check if it's in
|
||||||
origin_args = non_kw_param.parent.var_args.argument_node
|
# the tree (if not continue).
|
||||||
# TODO calculate the var_args tree and check if it's in
|
# print('\t\tnonkw', non_kw_param.parent.var_args.argument_node, )
|
||||||
# the tree (if not continue).
|
if origin_args not in [f.parent.parent for f in first_values]:
|
||||||
# print('\t\tnonkw', non_kw_param.parent.var_args.argument_node, )
|
continue
|
||||||
if origin_args not in [f.parent.parent for f in first_values]:
|
"""
|
||||||
continue
|
add_argument_issue(parent_context, 'type-error-too-many-arguments', lazy_context, message=m)
|
||||||
analysis.add(parent_context, 'type-error-too-many-arguments',
|
|
||||||
v, message=m)
|
|
||||||
return result_params
|
return result_params
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user