[Python-ideas] Please reconsider the Boolean evaluation of midnight
Shai Berger
shai at platonix.com
Wed Mar 5 19:44:55 CET 2014
On Wednesday 05 March 2014 20:33:08 Skip Montanaro wrote:
> On Wed, Mar 5, 2014 at 11:24 AM, Shai Berger <shai at platonix.com> wrote:
> > If your argument is not that "if obj:" should never be used, except
> > when obj actually is Boolean, please elaborate.
>
> My approach continues to be to consider the overall set of objects
> from which you draw values to assign to obj. Call that set V. If this
> expression is true:
>
> len([bool(x) for x in V]) == 1
>
> then using "if obj:" might be valid (if the one "false" value of that
> set is some sort of distinguishing characteristic, as it often
> is). If, however, the length of that set is greater than one, you must
> be explicit in your conditional expressions.
No argument so far.
> It is unfortunate for your purposes that bool(datetime.time(0, 0, 0)) is
> False, but it's a documented property of that object, and is highly unlikely
> to change.
I think this is what's called 'begging the question' -- this discussion was
not about the validity of boolean testing in general, but about the validity
of this property of time objects. Yes, it's documented. I'm trying to make it
change. There is a lot of support for that, and the opposition seems to be
centered on "because it's documented" -- with the two exceptions being an edge
use-case (actually checking midnight) and your call to authority below.
It's a gotcha. Let's remove it. If we don't remove it, let's give ourselves a
tool to detect it.
> My last comment on this topic. I will invoke the Uncle Timmy rule
> (which I just made up). Never contradict a decision Uncle Timmy
> made. He had his reasons. They were very good reasons. They were
> almost certainly better than any reasons you can come up with as
> counterarguments. Deal with it. :-)
>
The reason he actually gave (on the ticket)? "because it's documented".
Shai.
More information about the Python-ideas
mailing list