text stringlengths 0 828 |
|---|
# Check for presence of additional parameters in other |
# function |
if not (reference_varargs or reference_varkw): |
for other_arg in other_args: |
if other_arg not in reference_args: |
raise AutodiscoveryCheckerError( |
'Argument ""%s""' |
' in other function %s does not exist in the' |
' reference function %s' % |
(other_arg, other_object, reference_object)) |
# Check sorting of arguments |
for reference_arg, other_arg in map( |
None, reference_args, other_args): |
if not((reference_arg == other_arg) or |
(reference_arg is None and |
(reference_varargs or reference_varkw)) or |
(other_arg is None and |
(other_args or other_varargs))): |
raise AutodiscoveryCheckerError( |
'Argument ""%s"" in' |
' the other function is in the position of' |
' argument ""%s"" in the reference function, i.e.' |
' the order of arguments is not respected' % |
(other_arg, reference_arg)) |
if len(reference_defaults) != len(other_defaults) and not ( |
reference_args or reference_varargs or |
other_args or other_varargs): |
raise AutodiscoveryCheckerError( |
""Default parameters in"" |
"" the other function are not corresponding to the"" |
"" default of parameters of the reference function"") |
else: |
# We are comparing apples and oranges! |
raise AutodiscoveryCheckerError( |
'%s (the reference object)' |
' is a function while %s (the other object) is not a' |
' function' % (reference_object, other_object)) |
except AutodiscoveryCheckerError as err: |
try: |
sourcefile = inspect.getsourcefile(other_object) |
sourceline = inspect.getsourcelines(other_object)[1] |
except IOError: |
# other_object is not loaded from a real file |
sourcefile = 'N/A' |
sourceline = 'N/A' |
raise AutodiscoveryCheckerError( |
'Error in checking signature for' |
' ""%s"" as defined at ""%s"" (line %s): %s' % |
(object_name, sourcefile, sourceline, err))" |
4634,"def check_arguments_compatibility(the_callable, argd): |
"""""" |
Check if calling the_callable with the given arguments would be correct |
or not. |
>>> def foo(arg1, arg2, arg3='val1', arg4='val2', *args, **argd): |
... pass |
>>> try: check_arguments_compatibility(foo, {'arg1': 'bla', 'arg2': 'blo'}) |
... except ValueError as err: print 'failed' |
... else: print 'ok' |
ok |
>>> try: check_arguments_compatibility(foo, {'arg1': 'bla'}) |
... except ValueError as err: print 'failed' |
... else: print 'ok' |
failed |
Basically this function is simulating the call: |
>>> the_callable(**argd) |
but it only checks for the correctness of the arguments, without |
actually calling the_callable. |
:param the_callable: the callable to be analyzed. |
:type the_callable: function/callable |
:param argd: the arguments to be passed. |
:type argd: dict |
:raise ValueError: in case of uncompatibility |
"""""" |
if not argd: |
argd = {} |
args, dummy, varkw, defaults = inspect.getargspec(the_callable) |
tmp_args = list(args) |
optional_args = [] |
args_dict = {} |
if defaults: |
defaults = list(defaults) |
else: |
defaults = [] |
while defaults: |
arg = tmp_args.pop() |
optional_args.append(arg) |
args_dict[arg] = defaults.pop() |
while tmp_args: |
args_dict[tmp_args.pop()] = None |
for arg, dummy_value in iteritems(argd): |
if arg in args_dict: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.