Skip to content

Add additional ruff suggestions #1062

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

Merged

Conversation

Spaarsh
Copy link
Contributor

@Spaarsh Spaarsh commented Mar 14, 2025

WIP

18 ruff rules enabled, 4 need consideration and others are TODO

Which issue does this PR close?

Closes #1056

Rationale for this change

Need for enabling ruff rules.

What changes are included in this PR?

Enabled suggested ruff rules and changed the code to comply with them.

Are there any user-facing changes?

None.

Copy link
Contributor

@timsaucer timsaucer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, very nice. Thank you for doing this!

Comment on lines 165 to 168
if results is None:
results = resultant_arr
else:
results = pc.or_(results, resultant_arr)
results = (
resultant_arr if results is None else pc.or_(results, resultant_arr)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you double check this? It looks like it changed the logic slightly. If results is not None it doesn't look like this will work as before

pyproject.toml Outdated
Comment on lines 83 to 105
#"PT001",
# "ANN204",
# "B008",
# "EM101",
"PLR0913",
"PLR1714",
"ANN201",
"C400",
# "PLR1714",
# "ANN201",
# "C400",
"TRY003",
"B904",
"UP006",
"RUF012",
"FBT003",
"C416",
"SIM102",
"PGH003",
# "B904",
# "UP006",
# "RUF012",
# "FBT003",
# "C416",
# "SIM102",
# "PGH003",
"PLR2004",
"PERF401",
# "PERF401",
"PD901",
"EM102",
# "EM102",
"ERA001",
"SIM108",
"ICN001",
# "SIM108",
# "ICN001",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove the lines instead of commenting them out?

@@ -844,7 +842,7 @@ def register_csv(
file_compression_type: File compression type.
"""
if isinstance(path, list):
path = [str(p) for p in path]
path = [str(p) for p in path] if isinstance(path, list) else str(path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we're checking isinstance twice here

@Spaarsh
Copy link
Contributor Author

Spaarsh commented Mar 15, 2025

I don't understand why the ruff tests are failing. My local ruff check shows no errors.

@timsaucer
Copy link
Contributor

You may be using a different version of ruff. These do change from time to time as new lints get added in.

@Spaarsh
Copy link
Contributor Author

Spaarsh commented Mar 15, 2025

The workflow is using 0.9.1 and I pip install the same. Still I don't see any errors on my local tests.

@timsaucer
Copy link
Contributor

I’m not sure then. I’m away for the weekend and won’t be able to test until Monday. I can see then if I can reproduce.

@Spaarsh
Copy link
Contributor Author

Spaarsh commented Mar 15, 2025

The errors are due to one of the rules I enabled in one of my commits SIM102. Since I have some 10 other ruff rules to enable anyway, should I disable this one for now?

@timsaucer
Copy link
Contributor

Since we know this PR only addresses a portion of the rules we're working on, it seems perfectly reasonable to put it back into the ignore list for now.

@timsaucer
Copy link
Contributor

Thank you for all the work on this!

@timsaucer timsaucer merged commit b8dd97b into apache:main Mar 17, 2025
17 checks passed
@Spaarsh
Copy link
Contributor Author

Spaarsh commented Mar 17, 2025

@timsaucer there are still several rules to be enabled. But those require significant changes. Take a look at the rule PLR0913:

docs/source/conf.py:76:5: PLR0913 Too many arguments in function definition (6 > 5)
   |
76 | def autoapi_skip_member_fn(app, what, name, obj, skip, options) -> bool:  # noqa: ARG001
   |     ^^^^^^^^^^^^^^^^^^^^^^ PLR0913
77 |     skip_contents = [
78 |         # Re-exports
   |

This would require us to restructure these functions. There are 15 such errors.

Then there is rule ERA001 that requires us to remove commented out code.

Should I focus on enabling all rules anyway or should I consider the returns that we get on implementing these rules and proceed only if they are meaningful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apply additional ruff suggestions
2 participants