> There was talk about changing string (the base class) to something > else since it was the same name as the module. Was there ever a > decision made? Oops, no. Let's call it basestring. Can you do that? > Since I expect confusion between string (the module) and > string (the abstract class). The name issue is marginally > related to what's described below. > > Right now, if you derive a class from an instance (yes, this shouldn't work): > > >>> class x(5): pass > ... > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: int() takes at most 2 arguments (3 given) > > This makes sense and is what I would expect. > > But this is not what I would expect: > > >>> import string > >>> class newstr(string): pass > ... > # i would have expected this to raise a TypeError > >>> x = newstr() > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: 'module' object is not callable > > Perhaps this error should be handled when the class is constructed > rather than when instantiating an object? Can you submit a SF bug report for this? It has nothing to do with string per se -- the bug is that you can use any module as a base class. :-( > Of course, you can't derive from the string class either: > > >>> del string > >>> print string > <type 'string'> > >>> class x(string): pass > ... > >>> y = x() > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: The string type cannot be instantiated Thinking a little about this, I think this is how I want it to be. str and unicode have special status and it shouldn't be easy to create something else (not deriving from either) that also gets this special status. (You can still do it in C of course.) --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4