[Python-ideas] Adding collections.abc.Ordered

Nick Coghlan ncoghlan at gmail.com
Sun Dec 27 02:08:13 EST 2015


On 27 December 2015 at 12:20, Guido van Rossum <guido at python.org> wrote:
> On Sat, Dec 26, 2015 at 5:21 PM, Ben Finney <ben+python at benfinney.id.au>
> wrote:
>> So I advocate a class-level ‘foo = NotImplemented’ as an obvious way to
>> indicate an expected method is not implemented on this class.
>>
>> Thanks for discussing and explaining. My vote counts for whatever it
>> counts for, and I'll let these arguments stand or fall as I've presented
>> them.
>
> Thanks. I'm not convinced -- I think you're trying too hard to invent a
> special protocol for a pretty obscure corner case.

I was trying to recall if we'd ever seriously considered
NotImplemented for this use case, but as near as I can tell, the
"__hash__ = None" approach was born as the obvious Python level
counterpart of setting the C level tp_hash slot to NULL in Python 3.0:
https://hg.python.org/cpython/rev/c6d9fa81f20f/

We then retained the "__hash__ = None" behaviour at the Python level
even after switching to a custom slot entry at the C level as part of
resolving some corner cases that were found when backporting the abc
module from Python 3.0 to 2.6:
https://bugs.python.org/issue2235#msg69324

So this is a case of C's NULL pointer concept being visible in
Python's semantic model as "attribute = None". Operand coercion is
actually the special case on that front, as "None" needs to be
permitted as a possible result, and exceptions can't be used as an
alternative signalling channel due to the runtime cost involved.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list