[Python-Dev] The role of NotImplemented: What is it for and when should it be used? (original) (raw)
Guido van Rossum guido at python.org
Mon Nov 3 19:00:24 CET 2014
- Previous message: [Python-Dev] The role of NotImplemented: What is it for and when should it be used?
- Next message: [Python-Dev] The role of NotImplemented: What is it for and when should it be used?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
That must be so that an immutable type can still implement iop as an optimization.
On Mon, Nov 3, 2014 at 9:10 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
On Mon, 3 Nov 2014 09:05:43 -0800 Guido van Rossum <guido at python.org> wrote: > Sorry, was too quick. For immutable types iop may not exist and then > the fallback machinery should work normally using NotImplemented. But if > iop exists it can choose not to allow rop, because the type would > presumably change. This is probably more predictable. I don't even know if > the byte code interpreter looks for Not implemented from iop.
Apparently it can tell it to fallback on op: >>> class C(list): ... def iadd(self, other): ... print("here") ... return NotImplemented ... >>> c = C() >>> c += [1] here >>> c [1] >>> type(c) <class 'list'>
Regards Antoine.
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/guido%40python.org
-- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20141103/96c612e7/attachment.html>
- Previous message: [Python-Dev] The role of NotImplemented: What is it for and when should it be used?
- Next message: [Python-Dev] The role of NotImplemented: What is it for and when should it be used?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]