[Python-Dev] Possible wrong behavior of the dict?
Florian Bruhin
me at the-compiler.org
Tue Mar 17 20:33:46 CET 2015
* Zaur Shibzukhov <szport at gmail.com> [2015-03-17 22:29:07 +0300]:
> Yes... But I expected that dict constructor will use `__getitem__` or
> `items` method of MyDict instance in order to retrieve items of the MyDict
> instance during construction of the dict instance... Instead it interpreted
> MyDict instance as the dict instance during construction of new dict.This
> exactly caused my confusion.
Subclassing builtins is always a recipe for trouble, because the C
implementation doesn't necessarily call your Python methods.
You should probably use collections.UserDict or
collections.abc.(Mutable)Mapping instead:
https://docs.python.org/3/library/collections.html#collections.UserDict
https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping
Florian
--
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150317/aa7fc5a0/attachment.sig>
More information about the Python-Dev
mailing list