A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2016-June/145375.html below:

[Python-Dev] PEP 487: Simpler customization of class creation

[Python-Dev] PEP 487: Simpler customization of class creationINADA Naoki songofacandy at gmail.com
Tue Jun 21 19:09:09 EDT 2016
On Wed, Jun 22, 2016 at 2:50 AM, Raymond Hettinger
<raymond.hettinger at gmail.com> wrote:
>
>> On Jun 21, 2016, at 10:18 AM, Guido van Rossum <guido at python.org> wrote:
>>
>> Judging from Inada's message there seems to be some confusion about how well the compact dict preserves order (personally I think if it doesn't guarantee order after deletions it's pretty useless).
>
> Inada should follow PyPy's implementation of the compact dict which does preserve order after deletions (see below).

I follow it, for most cases.

When my compact dict doesn't preserve order is using PEP 412 Key sharing dict.


>>> class A:
...   ...
...
>>> a = A()
>>> b = A()   # a and b shares same keys, and have each values
>>> a.a = 1
>>> a.b = 2   # The order in shared key is (a, b)
>>> b.b = 3
>>> b.a = 4
>>> a.__dict__.items()
dict_items([('a', 1), ('b', 2)])
>>> b.__dict__.items()
dict_items([('a', 4), ('b', 3)])


It's possible to split keys when the insertion order is not strictly same.
But it decrease efficiency of key sharing dict.

If key sharing dict is effective only such a very strict cases,
I feel __slots__ can be used for it.
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4