-
Notifications
You must be signed in to change notification settings - Fork 144
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
Enable more ruff lint rules #2014
Conversation
After a brief reading, there are some checks I find arguable, I have questions WRT to some changes, but in general, the majority looks beneficial though, +1 to this effort from me. And here comes the "but"... I'm afraid it might be way too big for a reasonable review, as a single PR :( A collection of PRs, one for a commit/a group of similar commits (like 9ffff4d + ed34b66) - commits do seem to be very nicely rounded - would be easier to digest. Well, at least for me, YMMW. And we could discuss whether we do or do not enable a particular check. |
TBH, I'm even scared to start adding comments as I worry it might be very hard to address them e.g. in the middle one of those commits :) |
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.
Typo in a commit message: Fix flake8 C408: unnecessary collecion calls.
=> s/collecion/collection
Makes sense to me, but I'm no Polarion user. Sticking to UTC seems like a way less prone to misunderstandings.
Absolutely, with new linters & influx of waivers, let's communicate "the rules". Especially the comment with check ID & justification needs to be mentioned. I'd maybe add a new section before https://github.com/teemtee/tmt/blob/main/docs/contribute.rst#tests as pre-commit, linters involved, links and rules would consume a bit more than a single line, and they don't fit the tmt-ish nature of the "Tests" chapter. On the other hand, "Tests" does mention unit tests, maybe we could just structure "Tests" a bit - linters, unit tests, testsuite.
+1 for the former option.
I believe
Yeah, probably not a good candidate for implementation... (Especially when I for one prefer single quotes :)
I agree. I'm experimenting with
Depends. I'd give it a try, let's see what it reports, we can always disable some or even all checks.
Hm, here I'm worried about readability. Might be better for our code to use multiline strings & My thoughts on the rest of the commented-out checks:
|
23ecd38
to
3505bc0
Compare
Resolved new conflicts with main, @happz's remarks and updated ruff version, as it fixed one noqa. |
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've read through all the changes, looks good. Added just a few minor comments/questions.
`dict`, `list` or `tuple` calls can be rewritten as empty literals. The former is slower because the name `dict` must be looked up in the global scope in case it has been rebound.
Using `dict()`, `list()`, `set()` instead of dict/list/set comprehension.
ruff rule C401: It is unnecessary to use `set` around a generator expression, since there are equivalent comprehensions for these types. Using a comprehension is clearer and more idiomatic.
ruff rule C405: It's unnecessary to use a list or tuple literal within a call to `set`. Instead, the expression can be rewritten as a set literal.
Using the pyupgrade tool with --py36-plus argument. Not enabling the rule for lack of py36 support in ruff.
3505bc0
to
c57e1da
Compare
There are too many code changes required to make the checks pass and I don't really expect all of them to be accepted. It should be easy to drop whatever is deemed unnecessary, too strict or just not suitable for this project - probably better to review on per-commit basis.
I've tried to run the default set of tests, but my machine ran out of disk space 🤡, not going to claim I didn't break anything.
Polarion report UTC timezone
Not sure if make sense, but from what I understand the time stamp is being used to generate Title of the test run. Without timezone, I assume the datetime is naive, dependent on the OS settings/location of where the tmt is being run, resulting in potential mismatches, no?
Would it be beneficial to add a couple of lines in the contribute doc about ruff?
Maybe only mention when it's acceptable to add
noqa
(plus to add a comment why it's being added) and/or add a link to ruff rules page to keep it succinct?Alternatively, make it more verbose and also mention mypy?
Isort change being explained here
Can $maintainer(s) check the remaining, commented-out ruff rules in pyproject.toml. I think it would be nice if we could delete those not suitable for this project and keep only those that might get implemented in the future...Or just remove all of them.
Notes for some of the disabled checks:
TRY200, B904: Within an
except
clause, raise exceptions withraise ... from err
or `raise from None.I've actually tried to implement PEP-3134, as it looks like a good practice to me, but ultimately figured it's best to ask about it first.
Example of change in existing code:
changed to:
Q: flake8-quotes (Q000 Single quotes found but double quotes preferred) would need changes in basically whole codebase:
C90: mccabe (complex structure)
ANN: flake8-annotations - Some of the checks could compliment mypy.
S: flake8-bandit - Security/vulnerability checks tmt probably doesn't need?
ISC: ISC001 and ISC003 is actually passing already. Not sure if/how to adapt the code for ISC002 (Implicitly concatenated string literals over multiple lines)