-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: fix pylint message consider-using-any-or-all #881
chore: fix pylint message consider-using-any-or-all #881
Conversation
Thanks for the PR. |
It does not:
I’m curious: why would you? I think a loop is more code to read and more to write, so the cognitive load is higher. Once you get used to these built-in functions, the intention is clearer and they read more comfortably. For me, reading something like
I mildly disagree here: it’s the same argument for why folks use However, there isn’t always a performance benefit as you can read e.g. in this older discussion: performance depends on the complexity of the check and the interpreter you run. In the case of Macaron, it seems like the
I think it’s a good opportunity to expand “scope” from imperative C-style programming towards a more functional and abstract style of programming. Feel free to leave the PR open if you folks want to discuss this particular change more. |
I also find that using
That’s interesting! As we prepare to switch to Python 3.13 soon, we can also expect some performance benefits. |
It's just simply a personal preference. Just like how you believe in the benefits of using
Now if I did a for-loop style, the condition could be listed more explicitly that we accept empty list, but not "None" value.
With that being say, I completely understand that each of us has different personal preference and I totally respect that without disregarding the opposite argument.
I totally agree that given a group project, consistency is key. And if we (as a team) agree it's better to pursue the usage of |
Ok, there’s a lot to unpack here.
I avoid terms like “believe” because, quite frankly, opinions don’t matter much in a data-driven conversation. In this case, the lines of code can be quantified easily, and so can the runtime. Thus, we don’t need to “believe” that one is “better” than the other, we can objectively weigh data and the benefits of one over the other.
I believe (pun intended) that this will change as you read more Python code that makes more use of Python’s built-in functions.
You have to make that exact same cognitive effort when writing a I don’t understand the argument or the example that follows, so let me pick this apart.
An iterable produces values until it is exhausted (in which case it raises StopIteration). An iterable can not produce
Please rephrase more precisely, I don’t understand this statement. In this context, please also consider how Python implements truth value testing and the difference between “truthy” and “falsy” values — in your example, both
I don’t know what this example demonstrates: both
Here too, I don’t understand your statement. If the list was empty then neither >>> for i in []:
... print(i)
...
>>>
As I mentioned previously, this is not so much about “I like this, you like that” but it’s about consistency and performance and writing “pythonic” code. If Macaron folks decide to enable this code checker then it makes no sense to enable it here sometimes and disable it there sometimes, just because this developer has one preference and that developer another. We do not disable black randomly, and therefore should not disable these checkers randomly. The beauty of an opinionated toolchain is that developers’ opinions are moot, and code is consistent and thus easier to read and maintain.
Horribly wrong code is also valid Python code, but that doesn’t mean I want to write that.
At this point and with CPython and the miniture-use cases, no, there is not. But I think this conversation is also about creating the habit of questioning code instead of just blindly sticking with a habit. Python evolves, it adds features, it improves on existing features — we should be able to adapt to these changes instead of sticking with the old. Cheers. |
Thanks for the detailed response. I am happy to approve this PR. |
Signed-off-by: Jens Troeger <[email protected]>
996ec23
to
bc302f6
Compare
Signed-off-by: Jens Troeger <[email protected]>
This change is part of issue #876 and addresses the
consider-using-any-or-all
check messages.I’ll add the appropriate configuration to pyproject.toml in a separate PR later.