Sept. 27, 2019
7:03 p.m.
On Sep 27, 2019, at 10:15, MRAB <python@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.