[New-bugs-announce] [issue39149] False positive using operator 'AND' while checking keys on dict()
Leonardo Galani
report at bugs.python.org
Sat Dec 28 13:31:50 EST 2019
New submission from Leonardo Galani <leo at leonardobg.com.br>:
using Python 3.7.6 (default, Dec 27 2019, 09:51:07) @ macOs
dict = { 'a': 1, 'b': 2, 'c': 3 }
if you `if 'a' and 'b' and 'c' in dict: print('ok')` you will get a True, since everything is true.
if you `if 'a' and 'g' and 'c' in dict: print('ok')` you also get a True because the last statement is True but the mid statement is false.
To avoid this false positive, you need to be explicit:
`if 'a' in dict and 'g' in dict and 'c' in dict: print('ok')` you will get a false.
----------
components: macOS
messages: 358954
nosy: leonardogalani, ned.deily, ronaldoussoren
priority: normal
severity: normal
status: open
title: False positive using operator 'AND' while checking keys on dict()
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39149>
_______________________________________
More information about the New-bugs-announce
mailing list