[Python-Dev] The current dict is not an "OrderedDict"

Barry Warsaw barry at python.org
Tue Nov 7 14:48:01 EST 2017


Antoine Pitrou wrote:

> Well... It really depends what kind of problem you're solving.  I
> certainly delete or pop items from dicts quite often.
> 
> Let's not claim that deleting items from a dict is a rare or advanced
> feature.  It is not.

+1.  It's a pretty common pattern for handling optional keyword
arguments, e.g. in subclass methods.

class Foo(Bar):
    def foo(self, *args **kws):
        mine = kws.pop('mine', None)
        super().foo(self, *args, **kws)
        do_something_myself(mine)

Now the question is, what guarantees does the language make about the
ordering of kws that Foo.foo() is passing to Bar.foo()?

-Barry



More information about the Python-Dev mailing list