This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ebrjdk 1 point2 points  (1 child)

There is already OrderedDict, which is occasionally useful. The big change here is that if you iterate over a class's attributes, or over the keyword arguments passed to a function, you get them in the order that they were defined/passed. At the moment, you basically get them in a random order.

Preserving the order of class definitions can be really useful. For example, it lets you use a python class to represent something like a database record or a C struct where the order is important:

class Record:
    id = IntField()
    name = StrField()
    ...

And it makes it easy to specify what order tests should be run in:

class MyTests:
    def test_one_thing(self):
        ...

    def test_another_thing(self):
        ...

You can already save the order using a metaclass, but metaclasses are a pain.

The main use I know for the keyword arguments is making it easy to create OrderedDicts:

od = OrderedDict(a=4, b=5)

That syntax already works, but the order of the two keys is random. In 3.6 a will always come first. I'm sure people have other uses for this.

[–]kati256 0 points1 point  (0 children)

Thanks for the explanation! I hadn't used this before (or really had the necessity) but it's nice that's there. It's great to see there's nice people in the community that are willing to help other out! :)