-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Switch to use ruff #2795
Switch to use ruff #2795
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #2795 +/- ##
=======================================
Coverage 99.13% 99.13%
=======================================
Files 115 115
Lines 17206 17229 +23
Branches 3082 3084 +2
=======================================
+ Hits 17057 17080 +23
Misses 104 104
Partials 45 45
|
Opinion: ruff not supporting custom plugins is kind of a big deal for a project like trio, where we try to test, lint, etc. to fix future problems. But I haven't used ruff myself so I may be wrong to focus on that. |
ruff is surprisingly on top of mirroring the - functionality in a lot of flake8 plugins, I added a check to flake8-bugbear and in less than 24 hours it was added to ruff. But if there's a flake8 plugin we need that's not implemented I don't mind having flake8 just for that one plugin |
Is there anything I need to change in this PR for this? I didn't know trio used any plugins |
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.
Questions about configuration are probably because I don't know much about ruff
.
# noqa'd as it's an exported symbol | ||
# as it's an exported symbol, noqa'd |
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.
Is this something we should report to ruff? (something like "hey look if the comment doesn't start with noqa:
and it isn't just noqa
and the line is blank, it's probably just an explanation"?)
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 was more thinking about the open issue to make a But as jakkdl pointed out, we can just add that in at the time of. |
Quick note that |
fun fact: flake8-trio can now be run standalone: https://github.com/Zac-HD/flake8-trio#install-and-run-as-standalone |
# noqa'd as it's an exported symbol | ||
# as it's an exported symbol, noqa'd |
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.
# TODO: remove this once we have a py.typed file | ||
touch "$INSTALLDIR/py.typed" | ||
|
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 being a stickler I'd remove all the instances of generating/removing py.typed
in a dedicated PR.
You can allow certain ambiguous characters via [tool.ruff]
allowed-confusables = ["–"] |
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.
Accidentally reverted the noqa explanation fix
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'd recommend reverting the – changes - I think that's the more correct form of dash, using the ASCII character is just a poor substitute.
While I don't disagree in theory, I think standardizing and limiting the character set in code (as opposed to e.g. documentation) is very important for the sake of diffs and sanity of developers not used to differentiating them/don't have an easy way of inputting em-dash/using some bad font that makes them look similar/identical. If it was only allowed in docstrings and comments I'd be less hesitant, though either way is probably fine.
Co-authored-by: jakkdl <[email protected]>
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.
Really rough (haha, ruff) review. After these are resolved this should look good to me though.
@@ -13,8 +13,7 @@ cryptography>=41.0.0 # cryptography<41 segfaults on pypy3.10 | |||
black; implementation_name == "cpython" | |||
mypy; implementation_name == "cpython" | |||
types-pyOpenSSL; implementation_name == "cpython" # and annotations | |||
flake8 | |||
flake8-pyproject | |||
ruff >= 0.0.291 |
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.
Unless we're depending on some 0.0.291 functionality, I think we should not have a version constraint here -- the lockfile can have that for us!
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.
--format
is depreciated, 0.0.291 has the new version, --output-format
dcce938
|
||
|
||
@attr.s(eq=False, hash=False, slots=True) |
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.
Hmm unintentional new whitespace?
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 is a part of one of the formatting rules that says that there should always be two newlines between any new definitions in the global scope
== '''def combine_and(data: list[str]) -> str: | ||
"""Join values of text, and have 'and' with the last one properly.""" | ||
if len(data) >= 2: | ||
data[-1] = 'and ' + data[-1] | ||
if len(data) > 2: | ||
return ', '.join(data) | ||
return ' '.join(data)''' |
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.
To my untrained eye this looks the same as the file above. Maybe maybe a variable so you only have to type it once?
Also, just wondering where this sample code comes from!
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.
Checked and it is indeed identical, will make a variable shortly.
Sample code was in one of the files I have on my desktop when I'm testing things, but digging deeper it looks like a modified version of one of the functions from my discord bot (https://github.com/CoolCat467/StatusBot/blob/4c4a0808ecbba4bcd3a1a6f0bff8169bc8a2bbd5/src/StatusBot/bot.py#L169C1-L176C26)
Edit: To be more precise, this function's idea is used all over the place in a lot of my projects, usually when displaying lists of something to end users in a nice way, and is usually either specialized in joining the end with and
or with or
, and in a few iterations it's generic and can have the end be one of the inputs. combine_and
, combine_end
, and list_or
are all examples of different names I've used for this idea.
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.
Made variable in af0547a
This looks good! |
This PR has the project switch to using ruff instead of flake8 and handles the slight differences it has.
They have a quite compelling advertisement of sorts of why you should use their system in their readme, but in the end I use it myself in a lot of my projects because it's got nearly all the warnings flake8 does but also has autofix support, and it's way faster.