On Thursday, June 23, 2016 at 10:17:16 AM UTC+5:30, Lawrence D’Oliveiro wrote: > On Thursday, June 23, 2016 at 3:12:52 PM UTC+12, Larry Hudson wrote: > > On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote: > >> * boolean operators don’t have to operate on boolean values. The > >> language spec > >> <https://docs.python.org/3/reference/expressions.html#boolean-operations> > >> says: > >> > >> “...the following values are interpreted as false: False, None, numeric > >> zero of all types, and empty strings and containers (including strings, > >> tuples, lists, dictionaries, sets and frozensets). All other values are > >> interpreted as true.” > >> > >> I feel that’s a needlessly complicated rule. It would have been simpler if > >> boolean operators (and conditional expressions like in if-statements and > >> while-statements) only allowed values of boolean types. But that’s one of > >> the few warts in the design of Python... > > > > Wart?? I *strongly* disagree. I find it one of the strengths of Python, > > it enhances Python's expressiveness. > > Tightening it up would rule out a whole class of common errors, from > misunderstanding (or forgetting) the rule about what exactly gets interpreted > as true and what as false <https://bugs.python.org/issue13936> > <http://stackoverflow.com/questions/28116931/datetime-time0-0-evaluates-as-false-in-boolean-context>.
I would not support "tightening up" But calling a wart a wart seems like a good idea to me IOW making the docs a little more honest: Along these lines: There are two bool types in Python A first class bool that is useful for amusement, confusion and one-upping noobs A second class bool -- also called truthy and falsey -- that is used all the time -- https://mail.python.org/mailman/listinfo/python-list