Why does the **kwargs mapping compare equal with a differently ordered OrderedDict?

前端 未结 4 376
挽巷
挽巷 2021-01-17 12:00

According to PEP 468:

Starting in version 3.6 Python will preserve the order of keyword arguments as passed to a function. To accomplish this the coll

4条回答
  •  梦毁少年i
    2021-01-17 12:38

    "Ordered mapping" only means the mapping has to preserve order. It doesn't mean that order has to be part of the mapping's == relation.

    The purpose of PEP 468 is just to preserve the ordering information. Having order be part of == would produce backward incompatibility without any real benefit to any of the use cases that motivated PEP 468. Using OrderedDict would also be more expensive (since OrderedDict still maintains its own separate linked list to track order, and it can't abandon that linked list without sacrificing big-O efficiency in popitem and move_to_end).

提交回复
热议问题