[Python-Dev] the not operator (and the not special method) (original) (raw)
Guido van Rossum guido@python.org
Fri, 04 Oct 2002 08:39:21 -0400
- Previous message: [Python-Dev] the not operator (and the __not__ special method)
- Next message: [Python-Dev] PEP 285 (Adding a bool type) extending it further
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
This reminds me of an asymmetry between the bool type and other built-in types: the lack of a bool method.
Perhaps a bool method should be added to objects, just like int, str, long, float, complex and unicode. If bool is not defined bool() would fall back to using nonzero and len, just like str() falls back to using repr when str is not defined.
Apart from being a slightly odd name, nonzero does this; I see no reason to rename it to bool, since that would add nothing new -- it would only be cosmetics.
Would this be done in CPython with a new tpbool slot or special-cased like unicode and complex? Binary compatibility aside, I think it should be a slot. Boolean evaluation is a pretty basic operation.
I think it's actually a bad idea to allow types to define their booleanness independent from their numeric value (for numbers) or length (for containers).
--Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] the not operator (and the __not__ special method)
- Next message: [Python-Dev] PEP 285 (Adding a bool type) extending it further
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]