Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description Of Changes
setup.cfgtopyproject.tomlRuff is a Rust-based linter that is much faster. While speed isn't our primary concern (depending on how you feel about flake8 taking 5 seconds to run on our entire code base), it is nice to have it run instantly. It also makes it easier to migrate some linting to pre-commit as well. There's not much left on the basic flake8, and there is the prospect that we'll be able to migrate our custom flake8 plugin to this at some point in the future. Ruff also gives the option of automatically fixing some things. In fact, it fixed itself a lot of the code changes here--including removing our Python 2 handling/message, which seems fine at this point.
Ruff also can do some things like
pyupgradebut automatically based on the python version required in the package metadata inpyproject.toml, so I took the opportunity to migrate us as much as possible away fromsetup.cfg. Flake8 itself will likely never support this, so we're stuck with what we have until we fully drop flake8. The biggest hurdle right now is that Ruff's implementation of isort doesn't yet support controlling how line wrapping is done for imports.I also went ahead and fixed up the stacklevel "errors" that come from the new Bugbear version (Ruff also detects this--this closes #2966). Unfortunately, due to our extensive use of decorators, it's not trivial to determine the fixed stack level that gets to the user code, so I added a helper for warnings that does stack introspection to do this for us (based on similar code in Pandas). As an example of the stack level improvement, for this code:
it previously would give:
and now gives: