[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.

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

2019-12-28 Thread Ned Deily
Ned Deily added the comment: P.S. You should also read the "Operator precedence" section for expressions in the Python Language Reference manual which explains that comparison operators bind tighter than Boolean AND operators:

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

2019-12-28 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker ___ ___

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

2019-12-28 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: It's intended as non-empty strings evaluate to True so you with `'a' and 'b' and 'c' in dict` you are essentially evaluating `'a' and 'b' and ('c' in dict)` with brackets precedence i.e. `True and True and True` . On the other hand `'a' and 'g'

[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