[I18n-sig] Strawman Proposal: Smart String Test

M.-A. Lemburg mal@lemburg.com
Fri, 09 Feb 2001 11:26:07 +0100

Paul Prescod wrote:
> The types module will contain a new function called
> isstring(obj)
> types.isstring returns true if the object could be directly interpreted
> as a string. This is defined as: "implements the string interface and is
> compatible with the re regular expression engine."

re compatibility is given by read buffer compatibility; it is
not restricted to strings. In fact re works on buffers and mmap'ed
files too.

> At the moment no user
> types fit this criteria so there is no mechanism for extending the
> behavior of the types.isstring function yet. It's initial behavior is:
> def isstring(obj):
>     return type(obj) in (StringType, UnicodeType)

Looks like a hack which would only serve a temporary need...

The right thing to do would be to add a
new abstract string type object and then have isinstance() 
return 1 for StringType and UnicodeType when asked for the
new abstract type.

The problem with this approach is that we would be constructing
a forward compatible mechanism before having designed the
class hierarchie (see my other post) for these types, e.g.

                  binary data string (BinaryDataType)
                  text data string (TextDataType)
                    |           |
                    |           |
         Unicode string      encoded 8-bit string (with encoding 
         (UnicodeType)       (StringType)          information !)

Marc-Andre Lemburg
Company:                                        http://www.egenix.com/
Consulting:                                    http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/