forked from VimPlug/jedi
first version of too many arguments detection
This commit is contained in:
@@ -12,6 +12,7 @@ CODES = {
|
|||||||
'name-error': (2, NameError, 'Potential NameError.'),
|
'name-error': (2, NameError, 'Potential NameError.'),
|
||||||
'import-error': (3, ImportError, 'Potential ImportError.'),
|
'import-error': (3, ImportError, 'Potential ImportError.'),
|
||||||
'type-error-generator': (4, TypeError, "TypeError: 'generator' object is not subscriptable."),
|
'type-error-generator': (4, TypeError, "TypeError: 'generator' object is not subscriptable."),
|
||||||
|
'type-error-too-many-params': (4, TypeError, "TypeError: 'generator' object is not subscriptable."),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from jedi.parser import representation as pr
|
|||||||
from jedi.evaluate import iterable
|
from jedi.evaluate import iterable
|
||||||
from jedi import common
|
from jedi import common
|
||||||
from jedi.evaluate import helpers
|
from jedi.evaluate import helpers
|
||||||
|
from jedi.evaluate import analysis
|
||||||
|
|
||||||
|
|
||||||
def get_params(evaluator, func, var_args):
|
def get_params(evaluator, func, var_args):
|
||||||
@@ -110,6 +111,8 @@ def get_params(evaluator, func, var_args):
|
|||||||
# assignment, just the result. Therefore nothing has to be
|
# assignment, just the result. Therefore nothing has to be
|
||||||
# returned.
|
# returned.
|
||||||
values = []
|
values = []
|
||||||
|
if isinstance(var_args, pr.Array):
|
||||||
|
print var_args, var_args.start_pos
|
||||||
|
|
||||||
# Just ignore all the params that are without a key, after one keyword
|
# Just ignore all the params that are without a key, after one keyword
|
||||||
# argument was set.
|
# argument was set.
|
||||||
@@ -123,6 +126,14 @@ def get_params(evaluator, func, var_args):
|
|||||||
# create an Exception, but we have to handle that).
|
# create an Exception, but we have to handle that).
|
||||||
for k in set(param_dict) - keys_used:
|
for k in set(param_dict) - keys_used:
|
||||||
result.append(gen_param_name_copy(param_dict[k]))
|
result.append(gen_param_name_copy(param_dict[k]))
|
||||||
|
|
||||||
|
remaining_params = list(var_arg_iterator)
|
||||||
|
if remaining_params:
|
||||||
|
param_count = len(func.params)
|
||||||
|
message = 'TypeError: %s() takes exactly %s arguments (%s given).' \
|
||||||
|
% (func.name, param_count, param_count + len(remaining_params))
|
||||||
|
analysis.add(evaluator, 'type-error-too-many-params',
|
||||||
|
remaining_params[0][1], message=message)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
16
test/static_analysis/arguments.py
Normal file
16
test/static_analysis/arguments.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
def simple(a):
|
||||||
|
return a
|
||||||
|
|
||||||
|
simple(1)
|
||||||
|
simple()
|
||||||
|
#! 10 type-error-too-many-params
|
||||||
|
simple(1, 2)
|
||||||
|
|
||||||
|
|
||||||
|
def nested(*args):
|
||||||
|
return simple(*args)
|
||||||
|
|
||||||
|
nested(1)
|
||||||
|
nested()
|
||||||
|
#! 10 type-error-too-many-params
|
||||||
|
simple(1, 2, 3)
|
||||||
Reference in New Issue
Block a user