Re:What's New in Python 3.11?
by nxpnsv on Monday June 27, 2022 @05:07AM
(#31892165)
But why do you think you HAVE to use every new bell and whistle that comes with a new release? It seems like a stressful way to live
[ Parent
| on HN ]
even if I don't, I probably need to be able to understand and recognise them when other people do, in libraries/snippets etc that I depend on.
Not specifically a new feature, but I remember wasting a good bit of time when coming across a line that was essentially:
return headers.get('x-foo') == settings.FOO_KEY is not None
and being extremely confused until discovering it was a use of comparison chaining[1] and was actually doing the right thing.[1] https://docs.python.org/3.10/reference/expressions.html#comp...
Re:What's New in Python 3.11?
by Sohcahtoa82 on Monday June 27, 2022 @03:36PM
(#31899678)
> return headers.get('x-foo') == settings.FOO_KEY is not None
I'm a huge Python fanboy and this line is absolutely awful.
Comparison chains are great for stuff like "x < y < z" or "x == y == z", but the operators should never be mixed.
"Readability counts" is, IMO, the most important line in the Zen of Python, and that line is unreadable. I imagine it's equivalent to:
return headers.get('x-foo') == settings.FOO_KEY and settings.FOO_KEY is not None
Which, admittedly, feels like a clumsy line of code, but it's at least readable.