Author thomassen
Recipients docs@python, thomassen
Date 2017-06-29.13:36:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1498743378.1.0.0570911503542.issue30803@psf.upfronthosting.co.za>
In-reply-to
Content
The truth value of sets is not properly documented, in particular regarding whether an empty set is considered false or not.

Ignoring primitive (such as numerals) as well as user-defined types, https://docs.python.org/3/library/stdtypes.html#truth says:

> The following values are considered false:
> 
> - [...]
> - any empty sequence, for example, '', (), [].
> - any empty mapping, for example, {}.
> - [...]
> 
> All other values are considered true

According to https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range, a set is not a sequence (it is unordered, its elements do not have indices, etc.):

> There are three basic sequence types: lists, tuples, and range objects.

And, according to https://docs.python.org/3/library/stdtypes.html#mapping-types-dict,

> There is currently only one standard mapping type, the dictionary.

So, as per the documentation, the set type is not a type that can ever be False. However, when I try, bool(set()) evaluates to False.

When I asked this on Stack Overflow, someone checked in the CPython code and judged that this is most likely a mere documentation issue: https://stackoverflow.com/a/44813565/6867099
History
Date User Action Args
2017-06-29 13:36:18thomassensetrecipients: + thomassen, docs@python
2017-06-29 13:36:18thomassensetmessageid: <1498743378.1.0.0570911503542.issue30803@psf.upfronthosting.co.za>
2017-06-29 13:36:18thomassenlinkissue30803 messages
2017-06-29 13:36:17thomassencreate