-
Notifications
You must be signed in to change notification settings - Fork 530
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
STY: Enforce ruff rules #3690
base: master
Are you sure you want to change the base?
STY: Enforce ruff rules #3690
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3690 +/- ##
==========================================
+ Coverage 73.13% 73.14% +0.01%
==========================================
Files 1278 1278
Lines 59356 59345 -11
==========================================
- Hits 43411 43410 -1
+ Misses 15945 15935 -10 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
a6804a0
to
030f052
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10 comments, to avoid collapsing.
self.inputs.regularization_gradient_field_sigma, | ||
self.inputs.regularization_deformation_field_sigma, | ||
) | ||
return f"--regularization {self.inputs.regularization}[{self.inputs.regularization_gradient_field_sigma},{self.inputs.regularization_deformation_field_sigma}]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't strike me as more readable. Could do something like:
return f"--regularization {self.inputs.regularization}[{self.inputs.regularization_gradient_field_sigma},{self.inputs.regularization_deformation_field_sigma}]" | |
gfsigma = self.inputs.regularization_gradient_field_sigma | |
dfsigma = self.inputs.regularization_deformation_field_sigma | |
return f"--regularization {self.inputs.regularization}[{gfsigma},{dfsigma}]" |
Alternately, we could use format strings sensibly using input_spec
fields and then trait_get()
to populate them:
return f"--regularization {self.inputs.regularization}[{self.inputs.regularization_gradient_field_sigma},{self.inputs.regularization_deformation_field_sigma}]" | |
fmt = "--regularization {regularization}[{regularization_gradient_field_sigma},{regularization_deformation_field_sigma}]" | |
return fmt.format(**self.inputs.trait_get()) |
I would do this throughout. I don't think f-strings are improving things here, even if they might be very slightly more efficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I'm not very happy with these changes either. I can't decide whether I should disable UP0032 altogether and discard these changes, or apply the changes that make sense and silence the rest with noqa
. What would you do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do a per-file ignore, if it's only a couple files that get really ugly. Then we can revisit them separately or never. %
and str.format
aren't going away, so there's no time bomb if we end up just saying "ANTs is too special for UP032".
If it's broad, we could set the ignore to everything in "nipype/interfaces".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@effigies I still need to review all the UP032 changes and undo bad fixes.
Just realized this is still in draft. Will hold off on further review for now. |
9aa4484
to
8da086b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small suggestions.
8da086b
to
2fff982
Compare
B007 Loop control variable not used within loop body Co-authored-by: Chris Markiewicz <[email protected]>
B015 Pointless comparison at end of function scope. Did you mean to return the expression result?
B018 Found useless expression. Either assign it to a variable or remove it.
E741 Ambiguous variable name
FURB154 Use of repeated consecutive `global`
PLE0101 Explicit return in `__init__`
PLE1205 Too many arguments for `logging` format string
PT006 Wrong type passed to first argument of `@pytest.mark.parametrize`; expected `tuple`
PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`
PT014 Duplicate of test case in `@pytest_mark.parametrize`
Q000 Single quotes found but double quotes preferred
Q003 Change outer quotes to avoid escaping inner quotes
RUF100 Unused blanket `noqa` directive
UP008 Use `super()` instead of `super(__class__, self)`
UP032 Use f-string instead of `format` call Co-authored-by: Chris Markiewicz <[email protected]>
Disable some rules and postpone fixes.
2fff982
to
effe909
Compare
B010 Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
F522 `.format` call has unused named argument
F821 Undefined name
RUF100 Unused blanket `noqa` directive RUF100 Unused `noqa` directive
UP015 Unnecessary open mode parameters
UP025 Remove unicode literals from strings
for idx, value in enumerate(nonfinite_list): | ||
if idx == 0: | ||
track_points.append(nonfinite_list[idx]) | ||
track_points.append(value) | ||
else: | ||
track_points.append(nonfinite_list[idx] - nonfinite_list[idx - 1] - 1) | ||
track_points.append(value - last_value - 1) # noqa: F821 | ||
last_value = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're rewriting this loop, I'd stick with numpy arrays so we can just use vector operations until we need lists:
pts = np.ndarray(shape=(num_triplets, pt_cols), dtype="f4", buffer=all_str)
# Truncate last value
nonfinite = np.where(~np.isfinite(pts[:, 2]))[:-1]
track_points = [nonfinite[0], *(np.diff(nonfinite) - 1)]
return track_points, list(nonfinite)
@@ -64,7 +64,7 @@ def run_node(node, updatehash, taskid): | |||
# Try and execute the node via node.run() | |||
try: | |||
result["result"] = node.run(updatehash=updatehash) | |||
except: # noqa: E722, intendedly catch all here | |||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in general we would want to catch cases of E722 instead of blanket ignoring.
Summary
Disable some rules and postpone fixes.
Requires #3689.