def check_arguments_compatibility(the_callable, argd):
if not argd:<EOL><INDENT>argd = {}<EOL><DEDENT>args, dummy, varkw, defaults = inspect.getargspec(the_callable)<EOL>tmp_args = list(args)<EOL>optional_args = []<EOL>args_dict = {}<EOL>if defaults:<EOL><INDENT>defaults = list(defaults)<EOL><DEDENT>else:<EOL><INDENT>defaults = []<EOL><DEDENT>while defaults:<EOL><INDENT>arg = tmp_args.pop()<EOL>optional_args.append(arg)<EOL>args_dict[arg] = defaults.pop()<EOL><DEDENT>while tmp_args:<EOL><INDENT>args_dict[tmp_args.pop()] = None<EOL><DEDENT>for arg, dummy_value in iteritems(argd):<EOL><INDENT>if arg in args_dict:<EOL><INDENT>del args_dict[arg]<EOL><DEDENT>elif not varkw:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (<EOL>arg, get_callable_signature_as_string(the_callable), argd))<EOL><DEDENT><DEDENT>for arg in args_dict.keys():<EOL><INDENT>if arg in optional_args:<EOL><INDENT>del args_dict[arg]<EOL><DEDENT><DEDENT>if args_dict:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (<EOL>'<STR_LIT:U+002CU+0020>'.join(args_dict.keys()),<EOL>get_callable_signature_as_string(the_callable),<EOL>argd))<EOL><DEDENT>
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