Re: Test for structure
"Steven Bethard" <steven.bethard @gmail.com> wrote in message
news:GvKdnbutV6 lQt4ffRVn-jA@comcast.com. ..[color=blue]
> I don't like this idea much because it depends on str and unicode _not_
> having a particular function. I haven't seen any guarantee anywhere that
> str or unicode won't ever grow an __iter__ method. So this code seems
> dangerous as far as future compatibility goes.[/color]
When CPython's support for the old iteration protocol goes away, which I
expects it will someday, strings will have to grow an __iter__ method.
Even now, I think this difference between strings and lists is more of an
accident than a logical design. So the test is opaque and specific to
current CPython. The validity of something like a = a+'', however, is
inherent to the nature of strings.
Terry J. Reedy
"Steven Bethard" <steven.bethard @gmail.com> wrote in message
news:GvKdnbutV6 lQt4ffRVn-jA@comcast.com. ..[color=blue]
> I don't like this idea much because it depends on str and unicode _not_
> having a particular function. I haven't seen any guarantee anywhere that
> str or unicode won't ever grow an __iter__ method. So this code seems
> dangerous as far as future compatibility goes.[/color]
When CPython's support for the old iteration protocol goes away, which I
expects it will someday, strings will have to grow an __iter__ method.
Even now, I think this difference between strings and lists is more of an
accident than a logical design. So the test is opaque and specific to
current CPython. The validity of something like a = a+'', however, is
inherent to the nature of strings.
Terry J. Reedy
Comment