Message298099
Responding here to Peter's PR comment. Peter opened this issue with the claim that the doc failed a specific test case-- document the truth value of set(). Since mappings are (or can be viewed as) a specialized type of set, I always considered that the empty mapping line implicitly covered sets. But I acknowledge that this is not clear for everyone. The simplest fix to make the test pass would be: "any unordered collection, for example, set(), {}". This should also cover frozenset and a possible frozendict.
Raymond noted that 'user-defined' in the last bullet point is wrong (it implies that built-in functions are different) and should be deleted. He then combined the corrected rule for false with the default rule in the next sentence to produce a succinct statement of the actual rule. (In CPython, 'default' is literally true. Class 'object' has neither __bool__ nor __len__; ditto for all subclasses that do not add one.)
With a minor change, I like this statement and agree that it should be moved above the examples. But I think the bullet points should be reduced to just 3, rewritten, and single spaced, but not smashed into running text. I suggest replacing everything between the first sentence (ending with 'below.') and the last two (beginning with 'Operations') with:
"By default, an object is considered true unless its class defines either a __bool__ method that returns False or __len__ method that returns zero, when called with the object. Here are most of the built-in objects considered false.
* constants defined to be false: None and False.
* numeric 0 of any type: 0, 0.0, Decimal(0), Fractions(0, 1)
* empty sequences and collections: '', (), [], {}, set(), range(0)
"
Before writing the above, I checked that an instance attribute __bool__ = lambda: False is not consulted by bool(). |
|
Date |
User |
Action |
Args |
2017-07-11 02:03:21 | terry.reedy | set | recipients:
+ terry.reedy, rhettinger, docs@python, thomassen |
2017-07-11 02:03:20 | terry.reedy | set | messageid: <1499738600.99.0.800176443434.issue30803@psf.upfronthosting.co.za> |
2017-07-11 02:03:20 | terry.reedy | link | issue30803 messages |
2017-07-11 02:03:19 | terry.reedy | create | |
|