On Sun, Feb 23, 2020 at 08:51:55PM -0000, Steve Jorgensen wrote:
The only change I am proposing is that the iterability for characters in a string be moved from the string object itself to a view that is returned from a `chars()` method of the string. Eventually, direct iteratability would be deprecated and then removed.
I do not want indexing behavior to be moved, removed, or altered, and I am not suggesting that it would/should be.
You can't have both of those behaviours at the same time. Well, technically you might be able to get that to work[1], but it would be awfully surprising. Fundamentally, iteration is equivalent to repeated indexing. To break that invariant would make strings the mother of all special cases breaking the rules. Python has not just the "iterator protocol" using `__iter__` and `__next__`, but also has an older sequence protocol used in Python 1.x which still exists to this day. This sequence protocol falls back on repeated indexing. Conceptually, we should be able to reason that every object that supports indexing should be iterable, without adding a special case exception "...except for str". [1] Setting `__iter__` to None, or having it raise TypeError, appears to work. Although perhaps it shouldn't? -- Steven