I need to make sure all the named parameters were passed to a method (I don’t want any defaults). Is the following the best way to enforce it?
class X:
def func(self, **kwargs):
if set(kwargs.keys() != ('arg1', 'arg2', 'arg3'):
raise ArgException(kwargs)
For Python 2.x, Hugh’s answer (i.e. just use named positional arguments) is your best bet.
For Python 3.x, you also have the option of requiring the use of keyword arguments (rather than merely allowing it) as follows: