On Sat, Jul 25, 2020 at 12:58 PM Guido van Rossum <gu...@python.org> wrote:
> On Sat, Jul 25, 2020 at 12:45 PM Marco Sulla <marco.sulla.pyt...@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.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/4XU3IECSVNQLFU2JWXLJY7A4ZRCTKPXM/ Code of Conduct: http://python.org/psf/codeofconduct/