-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
SIM108 turns readable code into unreadable code #5528
Comments
Perhaps I am in the minority on this, but I prefer the ternary syntax in the example here, so I would prefer any change to this to be optional. |
I'm open to an argument that we should only apply this rule when the test is a single condition (since the |
Can’t you just use noqa as needed? The simplify rules are opinionated. Usually those long expressions are ‘variable = value condition or None’ anyway - my mental model has adjusted. |
Devs in our organization also complained about it. While great for simple conditions and expressions, the longer they become, the messier and harder to read it makes the code. I see @charliermarsh is not a fan of configurability for this one, but imo any way to control a maximal complexity level (of either the condition or the return values) would make it a great addition. |
In a former company we had the (code style) rule that ternary expression could only be a single line and only "simple" conditions or assignments (e.g. something like |
This style of response isn't helpful. It fits the pattern: "Can't you just use <an inferior solution the requester certainly knows about and has rejected it> instead? <here goes an explanation why the troublesome feature should stay as it is and we shouldn't try to improve it>" It should be clear that the person reporting the issue knows about noqa, and finds the use of noqa to be deficient, hence they're reporting the issue. Why is noqa a non-solution:
|
You’re right, that wasn’t a very considerate suggestion. I’ve enjoyed SIM108, but I’d understand if someone else wanted a more robust solution than “use noqa”. |
I find the issue to be formatting related with long ternary conditionals. For example in JS/TS with ESLint I force-wrap all ternaries, but with Python having to add extra parenthesis (which are formatted on their own lines), or |
I agree, but I suggest writing the ternary expression as: runner_image = (something[0].url
if something is not None and len(something) > 1
else None) I propose that this is more legible and briefer than the original code. (I hope we keep SIM108 in all cases.) |
The rule should only apply to trivial conditions with the simplest expressions (e.g. even having 2 sub-expressions joined with
and
oror
is too much).a.py:
cmd:
ruff --isolated --select SIM --line-length=120 a.py
Output:
My eyes refuse to read
runner_image = something[0].url if something is not None and len(something) > 1 else None
.The text was updated successfully, but these errors were encountered: