[Python-Dev] Classes that claim to be defined in builtin but aren't (original) (raw)
Guido van Rossum guido at python.org
Sun Aug 15 08:33:13 CEST 2004
- Previous message: [Python-Dev] Classes that claim to be defined in __builtin__ but aren't
- Next message: [Python-Dev] Classes that claim to be defined in __builtin__ but aren't
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Guido van Rossum wrote:
>>Sooo should (for 'generator' in objects that claim to be in >>builtins but aren't), >>1) 'generator' be added to builtins >>2) 'generator' be added to types.py and its module be set to 'types' >>3) 'generator' be added to .py and its module be set to >>'' (and a name for the module chosen) > > I guess (1).
[Note: it should be added to builtin, not builtins -- the two are related but builtin is the module and builtins is a secret attribute that references the module or its dict for purposes of sandboxing.
[Brett C]
The problem I see with explicitly adding this stuff to builtins is that tab-completion in the interpreter is suddenly going to have all of this extra stuff that people are not going want to really see that often.
There's already lots of stuff there that's rarely used.
The other point I would like to make is that almost everything in builtins is either an exception, a singleton (thinking of True and False), or a function (even thinking of list and dict since you can use their factory methods).
But list and dict are not functions, they are types, and they can be used for subclassing and type checking too. These are the precedent for placing generator etc. in builtin.
The only exceptions I can think of are name and that is just part of the design. Throwing in generator and any of the other types that are defined by the built-in types will go against all of this unless we create factory methods for them which is not really desired since they are returned only in certain situations.
They should not be made factory functions if they aren't already.
I personally prefer option 2.
Bah. The types module shouldn't be the "home" for any types -- it's just a collection of convenient aliases, and mostly they have the wrong names. It should be deprecated.
Also note that at least 6 of these "anonymous" built-in types currently have another alias in the 'new' module, which means that they are factories already. It would be nice if that module could finally be deprecated.
--Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] Classes that claim to be defined in __builtin__ but aren't
- Next message: [Python-Dev] Classes that claim to be defined in __builtin__ but aren't
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]