Lennart Regebro wrote:
> 1. A() < B() will call A.__lt__(B) which will return NotImplemented.
> 2. which will mean that Python calls B.__ge__(A)
> 3. Which B implements by doing A < B
> 4. Start over at 1.
> 
> 
> Have I missed something, or is this recipe incomplete by not handling
> the NotImplemented case? If it is, I think the recipe should be
> changed to something that handles it.

I tested both the recipe linked from the docs and Raymond's shorter
recipe at http://code.activestate.com/recipes/576685/ and sure enough
both suffer from infinite recursion if the root method returns
NotImplemented when two of those items are being compared.

However, returning NotImplemented generally implies that A and B are
*different* classes, so I think this is more of a theoretical problem
than a practical one.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
---------------------------------------------------------------

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to