<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Aug 21, 2016 at 2:53 AM Michael Selik <<a href="mailto:michael.selik@gmail.com">michael.selik@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Sun, Aug 21, 2016 at 2:46 AM eryk sun <<a href="mailto:eryksun@gmail.com" target="_blank">eryksun@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sun, Aug 21, 2016 at 6:34 AM, Michael Selik <<a href="mailto:michael.selik@gmail.com" target="_blank">michael.selik@gmail.com</a>> wrote:<br>
> The detection of not hashable via __hash__ set to None was necessary, but<br>
> not desirable. Better to have never defined the method/attribute in the<br>
> first place. Since __iter__ isn't present on ``object``, we're free to use<br>
> the better technique of not defining __iter__ rather than defining it as<br>
> None, NotImplemented, etc. This is superior, because we don't want __iter__<br>
> to show up in a dir(), help(), or other tools.<br>
<br>
The point is to be able to define __getitem__ without falling back on<br>
the sequence iterator.<br>
<br>
I wasn't aware of the recent commit that allows anti-registration of<br>
__iter__. This is perfect:<br>
<br>
>>> class C:<br>
... __iter__ = None<br>
... def __getitem__(self, index): return 42<br>
...<br>
>>> iter(C())<br>
Traceback (most recent call last):<br>
File "<stdin>", line 1, in <module><br>
TypeError: 'C' object is not iterable<br>
>>> isinstance(C(), collections.abc.Iterable)<br>
False<br></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>For that to make sense, Iterable should be a parent of C, or C should be a subclass of something registered as an Iterable. Otherwise it'd be creating a general recommendation to say ``__iter__ = None`` on every non-Iterable class, which would be silly.</div></div></div></blockquote><div><br></div><div>I see your point for avoiding iterability when having __getitem__, but I hope that's seen as an anti-pattern that reduces flexibility.</div><div><br></div><div>And I should learn to stop hitting the send button halfway through my email.</div></div></div>