[BangPypers] Enforcing keyword only arguments
sudheer.zzz at sudheer.net
Wed Aug 10 16:00:59 EDT 2016
Python 3 has this nifty feature of including the * in the argument list
to indicate the end of positional arguments and the beginning of
def my_func(a, b, *, kw1=None, kw2=None): pass
In Python 2 you could achieve the same goal of enforcing keyword-only
arguments using a technique like below example function:
def my_func(a, b, **kwargs):
kw1 = kwargs.pop('kw1', None)
kw2 = kwargs.pop('kw2', None)
Would you consider this technique of enforcing keyword-only argument in
Python 2 idiomatic?
I understand that it could be a matter of personal taste. But I'm
curious to know what other Python programmers think about it.
More information about the BangPypers