On Sat, Jul 25, 2020 at 12:58 PM Guido van Rossum email@example.com wrote:
On Sat, Jul 25, 2020 at 12:45 PM Marco Sulla Marco.Sulla.Python@gmail.com wrote:
I also remembered another possible use-case: kwargs in CPython. In C code, kwargs are PyDictObjects. I suppose they are usually not modified; if so, fdict could be used, since it seems to be faster at creation.
That's an interesting idea. It has always vaguely bothered me that `*args` gives a tuple while `**kwds` gives a dict. Unfortunately it's impossible to change without breaking tons of existing code, since things like `kwds.pop("something")` have become a pretty standard idiom to use it.
And just to be clear for folks that don't know the idiom (it took me a second to remember myself), it's common to do something like:
def spam(**kwargs): """Do 'something', then call bacon().""" if 'something' in kwargs: use_something(kwargs.pop('something') bacon(**kwargs)
def bacon(**kwargs): ...
You see this in decorators, for instance, that add an extra argument to do some pre-processing or something before calling the decorated function.