I have even shorter answer, with my favorite python feature - decorators:
def single_keyword(func):
def single_keyword_dec(*args, **kw):
if len(kw) > 1:
raise Exception("More than one initializer passed: {0}".format(kw.keys()))
return func(*args, **kw)
return single_keyword_dec
@single_keyword
def some_func(self, foo=None, bar=None, baz=None):
print foo, bar, baz
some_func(object, foo=0)
some_func(object, foo=0, bar=0)
#result
0 None None
Traceback (most recent call last):
File "dec2.py", line 13, in <module>
some_func(object, foo=0, bar=0)
File "dec2.py", line 4, in single_keyword_dec
raise Exception("More than one initializer passed: {0}".format(kw.keys()))
Exception: More than one initializer passed: ['foo', 'bar']
If you need distinguish between 'foo', 'bar', 'baz' and some other keywords, you could make similiar decorator which would accept list of keywords to restrict, and use it like this: @single_keyword('foo', 'bar', 'baz')
This way its 100% code reuse, no typing same thing over and over, and you get proper keywords in your function, not some obscure dict.