I mean, this is the form of a very common mistake as well - one that even senior developers make. I am sympathetic to the linter, even though I use this form in C++ quite a bit.
The issue of course is that this is a silly way to do loops, not just because of the condition but because it conflates "falsey" and "being None
". By now it's a legacy that everyone knows, but it should just be something like for (kid of li.children) {}
.
Don't get me wrong, I'd still write it the way you do, it’s the best way, it’s just a shame the language is set up that way. Python has the advantage of requiring the :=
operator for such assignments, so there is no ambiguity.
Overall, as a very senior developer (I started writing code in the 1970s), I consider it my role to set a good example and not to dumb my code down, but I do avoid obscure things, and I also avoid making unnecessary, uninstructive work for juniors.
As an example, I wrote some Python yesterday that went like this:
return name, value or name
Now, I know in my heart that or
has a higher operator priority than ,
, but I also want this code to be an easy read and I know that even experienced programmers are iffy about operator priorities around the edges, so I later rewrote it as
return name, (value or name)
before I made a pull request.