[issue39149] False positive using operator 'AND' while checking keys on dict()

2019-12-28 Thread Leonardo Galani


New submission from Leonardo Galani :

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 
<https://bugs.python.org/issue39149>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39149] False positive using operator 'AND' while checking keys on dict()

2019-12-28 Thread Leonardo Galani


Leonardo Galani  added the comment:

I would totally agree if it wasn't for this:

>>> 'a' and 'b' and 'g' in dict
False

The last evaluation is False, making the whole statement False.

but thanks for the documentation link and stackoverflow suggestion.
it sure does make the code more readable.

Happy new year!

--

___
Python tracker 
<https://bugs.python.org/issue39149>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com