New submission from Peter Thomassen:

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

----------
assignee: docs@python
components: Documentation
messages: 297268
nosy: docs@python, thomassen
priority: normal
severity: normal
status: open
title: Truth value of sets not properly documented
type: enhancement
versions: Python 3.5, Python 3.6, Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30803>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to