On Sep 27, 2019, at 10:15, MRAB <pyt...@mrabarnett.plus.com> wrote:
> 
>> On 2019-09-27 17:05, Steven D'Aprano wrote:
>> 
>> But doing it correctly is too painful:
>>     if any(getattr(T, '__getitem__', None) is not None for T in 
>> type(obj).mro())
> [snip]
> 
> Is there are reason why you're using 'getattr' instead of 'hasattr'?

There is a difference here: if some class defines __getitem__ = None, blocks it 
from looking like a subscriptable type.

That idiom is used for other things like __hash__, even if it’s not used 100% 
consistently for all protocols. 

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/FBWRI6GQ2LZ64LADQOVFFKWRNFWYEZOX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to