On Sun, Aug 21, 2016 at 3:06 PM, Brendan Barnwell <brenb...@brenbarn.net> wrote:
> On 2016-08-20 21:10, Chris Angelico wrote:
>>>
>>> >I think that while the suggestion does bring some benefit, the benefit
>>> >isn't enough to make up for the code churn and disruption it would
>>> >cause. But I encourage the OP to go through the standard library, pick a
>>> >couple of modules, and re-write them to see how they would look using
>>> >this proposal.
>>
>> Python still has a rule that you can iterate over anything that has
>> __getitem__, and it'll be called with 0, 1, 2, 3... until it raises
>> IndexError. So you have two options: Remove that rule, and require
>> that all iterable objects actually define __iter__; or make strings
>> non-subscriptable, which means you need to do something like
>> "asdf".char_at(0) instead of "asdf"[0].
>
>
>         Isn't the rule that that __getitem__ iteration is available only if
> __iter__ is not explicitly defined?  So there is a third option: retain
> __getitem__ but give this new modified string type an explicit __iter__ that
> raises TypeError.

Hmm. It would somehow need to be recognized as "not iterable". I'm not
sure how this detection is done; is it based on the presence/absence
of __iter__, or is it by calling that method and seeing what comes
back? If the latter, then sure, an __iter__ that raises would cover
that.

ChrisA
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to