PEP 285: Adding a bool type: yes, but not as int subtype
Kris J. Zaragoza
kzaragoza at attbi.com
Mon Apr 1 17:38:39 EST 2002
In article <a8akqh$8bk$0 at 216.39.172.122>, Bengt Richter wrote:
> Of course the 'hidden property' is only rhetoric here, but why not
> make this a clear and controllable unified mechanism instead of a
> collection of special effects? I would like to see an overridable
> __bool__ method (not actually a programmatic property) for the base
> object class, perhaps making deprecation of __nonzero__ possible.
Now this is an idea with some merit. I can see some real advantages
to being able to define the truth value of a given object, or at least
control its conversion to a bool. But then, Guido's PEP already shows
this as possible when creating a bool. If you look at the __new__()
constructor, it checks the truth value of the object when deciding
which global value to return. If this is how things are implemented
in the C code (and I haven't checked), then __nonzero__() (or
__len__()) is called if defined. This gives us the control we're
looking for.
> Well, what do you think of the above?
It certainly clarifies matters a bit, but I still have to wonder
whether it's worth the effort. The way I see it, the mechanism for
the customizations you describe is already present, albeit badly
named.
I certainly don't object to implementing the bool type. I guess I
just don't see it as a significant advantage.
Kris
--
Kris J. Zaragoza | On the face of it, Microsoft complaining about
kzaragoza at attbi.com | the source license used by Linux is like the
| event horizon calling the kettle black.
| -- Adam Barr, article on kuro5hin.org
More information about the Python-list
mailing list