> On Dec 31, 2019, at 05:50, iman.h.a.kha...@gmail.com wrote: > > if foo or bar or baz in foobar: > pass > if foo and bar and baz in foobar: > pass > > maybe for "is" instead of: > > if foobar is foo or foobar is bar or foobar is baz: > pass > > if foobar is foo or bar or baz: > pass > > now the recommended syntax translate to this: (I think so) > > if foo (IS NOT '0' or None or empty) or bar (IS NOT '0' or None or empty) or > baz in foobar
I’m not sure what this translation is supposed to mean, since that isn’t valid Python syntax or meaningful English, but it does seem like you’re trying to say something that’s pretty close to what’s right. foo or bar or baz in foobar … is roughly … foo if foo else (bar if bar else (baz in foobar)) And that “if foo” is true for most types unless foo is False, None, an empty collection, or a numeric zero (but not the string '0'; that’s perfectly truthy). While this seems silly with meaningless names, the exact same syntax is often useful: if already_found or child.find(key) or key in known_bad_keys: Surely this has to mean that we’re checking whether a flag is true, or a find function finds something, or a key is a known bad key, not whether any of the flag, the value found by the function, or the key are known bad keys. And that’s exactly why this syntax is ambiguous not just to the parser, but to humans. In most cases the existing meaning makes sense. In some cases, your meaning makes sense. If there’s any overlap between the two sets of cases, both make sense, so it’s ambiguous. Even if you can find a way to reliably disambiguate, that’s still an extra concept that the reader has to think through to understand your code. At which point, even if it’s fewer characters than using a set operator where it makes sense, or a generator expression inside any otherwise, it’s still not more readable. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/RXJBCVYKVW6SFCU7XDJD7SF4SCWYLEE5/ Code of Conduct: http://python.org/psf/codeofconduct/