Test for structure

Terry Reedy tjreedy at udel.edu
Mon Feb 21 15:25:22 EST 2005


"Steven Bethard" <steven.bethard at gmail.com> wrote in message 
news:GvKdnbutV6lQt4ffRVn-jA at comcast.com...
> 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.

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






More information about the Python-list mailing list