[Python-Dev] Removing types module from stdlib

Guido van Rossum guido@python.org
Fri, 31 May 2002 15:42:43 -0400


> I use this little toy on occasion:
> 
> class istr(str):
>   __slots__ = ()
>   def __hash__(self):
>     return hash(self.lower())
>   def __eq__(self, other):
>     return self.lower() == other.lower()
>   def __ne__(self, other):
>     return self.lower() != other.lower()
>   def __le__(self, other):
>     return self.lower() <= other.lower()
>   def __ge__(self, other):
>     return self.lower() >= other.lower()
>   def __lt__(self, other):
>     return self.lower() < other.lower()
>   def __gt__(self, other):
>     return self.lower() > other.lower()
> 
> Are you saying that you want to outlaw it?

No, subclassing str (or unicode) is fine, because then you inherit the
implementation properties.

I want to outlaw (or at least discourage) creating new subclasses of
the basestring type (in current CVS it's called string, but it will be
renamed soon).

If someone writes isinstance(x, basestring) they should be confident
that x is either a str, a unicode, an instance of a subclass of those,
or something written in C that works real hard to look like a string.

--Guido van Rossum (home page: http://www.python.org/~guido/)