1
0
forked from VimPlug/jedi

first version of too many arguments detection

This commit is contained in:
Dave Halter
2014-05-21 12:30:51 +02:00
parent a252d825f2
commit 4ecc150d85
3 changed files with 28 additions and 0 deletions

View File

@@ -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."),
} }

View File

@@ -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

View 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)