| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
I'm generally in favour!
Sorry, something went wrong.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Me too! Note there's some overlap with #121241 which @AlexWaygood wanted to post about on Discourse first. I'm also fine with not doing so. |
Sorry, something went wrong.
Is that the right issue/PR? I don't see a mention of Ruff on it. |
Sorry, something went wrong.
|
I'm specifically nervous about enabling more aggressive linting on stdlib modules in Lib/, as I think it's important we get consensus among core devs before going ahead with that more broadly. For stuff in Tools/ and Doc/, I think it's fine to enable as much linting/formatting as we like. This is all purely internal tooling, so the stakes are lower, the stakeholders are fewer, keeping a clean git blame is less important, etc. |
Sorry, something went wrong.
There was a problem hiding this comment.
I would personally go for quote-style = "preserve", and switch to quote-style = "double" in a followup, rather than going for quote-style = "single" (https://github.com/python/cpython/pull/122018/files#r1684185495). But I don't feel strongly. LGTM!
Sorry, something went wrong.
|
Thanks @AA-Turner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
Sorry, something went wrong.
|
Sorry, @AA-Turner, I could not cleanly backport this to 3.13 due to a conflict. cherry_picker 40855f3ab80ced9950c725b710f507c0e903b70a 3.13 |
Sorry, something went wrong.
|
Sorry, @AA-Turner, I could not cleanly backport this to 3.12 due to a conflict. cherry_picker 40855f3ab80ced9950c725b710f507c0e903b70a 3.12 |
Sorry, something went wrong.
|
Thanks @AA-Turner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Sorry, something went wrong.
|
Thanks @AA-Turner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, something went wrong.
|
Sorry, @AA-Turner, I could not cleanly backport this to 3.12 due to a conflict. cherry_picker 40855f3ab80ced9950c725b710f507c0e903b70a 3.12 |
Sorry, something went wrong.
|
GH-122023 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
|
GH-122024 is a backport of this pull request to the 3.12 branch. |
Sorry, something went wrong.
…ythonGH-122018) (cherry picked from commit 40855f3) Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Alex Waygood <Alex.Waygood@gmail.com>
|
No problem :) |
Sorry, something went wrong.
|
I got a lint failure on a PR: Ruff (I001) Doc/tools/version_next.py:15:1: I001 Import block is un-sorted or un-formatted As far as I know, the import block is OK according to PEP 8. When adding checks like this, could you also add some instructions to the devguide about how to deal with the warnings -- preferably without installing third-party tools I might not trust? |
Sorry, something went wrong.
|
@encukou, I'm sorry if we rushed this. Sorry that the error was inscrutable; thanks for flagging.
We already have documentation in the devguide noting that we have pre-commit checks set up, and giving some instructions about setting up pre-commit locally:
(I personally tend to avoid actually installing pre-commit hooks myself -- I usually run pre-commit run -a to fix all linting issues.)
Our CI is setup so that generally pre-commit will show you the changes it wants you to make to your PR as a diff when CI fails. In this case, it looks like that didn't happen for #121278. I'm not sure why that is, but anyway -- it's telling you that your imports aren't alphabetically sorted. You can find the documentation for the I001 Ruff rule here (I googled "Ruff I001"). |
Sorry, something went wrong.
Thanks! I filed python/devguide#1360 to improve the set-up instructions. (If you don't do it yourself, is installing pre-commit as a commit hook the right thing to do?)
I don't understand why it is important to sort imports alphabetically. |
Sorry, something went wrong.
It's a thing that many people like to do. The advantage is that you don't have to run the linter manually; it automatically applies any autofixes as part of running git commit. The disadvantage is that you don't have to run the linter manually -- automatically applying autofixes as part of git commit is a bit too magical for my tastes. I prefer to see explicitly what changes the autofixer has made when I'm working on a patch locally. Running pre-commit run -a explicitly runs all linters that we have listed in our .pre-commit-config.yaml file, and that's what I prefer. I wasn't involved in the decision to add a section to the devguide telling people to setup commit hooks to run pre-commit.
It's not particularly important, but many people have decided that it's something they want to enforce as a matter of style. I personally like to enforce a consistent style of imports in this way in the projects I maintain, but I also wouldn't be distraught if we got rid of this rule.
PEP 8 is the style guide for the standard library, and we're not enforcing this rule on the standard library -- only internal tooling in the Doc/ directory. |
Sorry, something went wrong.
| name: Run Ruff (lint) on Argument Clinic | ||
| args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml] | ||
| files: ^Tools/clinic/|Lib/test/test_clinic.py | ||
| - id: ruff-format |
There was a problem hiding this comment.
@AA-Turner in pre-commit, it's usually best to put formatters before linters. This is because if there's a rule violation that linter shows, it will then show up as two different broken checks. It's also more important for the post-format version to be checked rather than showing errors on things that then get changed/relocated.
Sorry, something went wrong.
There was a problem hiding this comment.
Oh, are the pre-commit tools not idempotent? I hadn't realised that order mattered, as I thought we'd configured them to check only in a read-only fashion.
As you can probably tell, I don't use pre-commit personally!
A
Sorry, something went wrong.
There was a problem hiding this comment.
The Ruff pre-commit README says:
When running with --fix, Ruff's lint hook should be placed before Ruff's formatter hook, and before Black, isort, and other formatting tools, as Ruff's fix behavior can output code changes that require reformatting.
When running without --fix, Ruff's formatter hook can be placed before or after Ruff's lint hook.
Sorry, something went wrong.
There was a problem hiding this comment.
@AA-Turner oh, I didn't realize. It's so popular that I tend to forget there's people who don't use it. I think I first contributed to pre-commit in 2016…
But yeah, there's science to crafting a config for the pre-commit tool. And there are a few principles I found very useful in this context. Here's how I sort the entries:
pre-commit itself does not modify things by itself, so you can say it's idempotent in this sense. It's the checks that call other tools that modify files. I think if a check changes files (pre-commit docs sometimes call these “fixers”, not “formatters”), pre-commit will then show that entry as failed (although, it probably relies on the called program's return code). When something changed, it's useful to know what, so it's best to call the tool with --show-diff-on-failure. I think the https://pre-commit.ci web service does this by default (this service is also able to push a commit with the changed files back to pull requests, by the way). Some people only use this CLI flag in CI, while others stick it into the command runner like tox so it's active locally when the contributors run linting.
Feel free to tag me for reviews in future PRs if you need any more insight on this topic.
Sorry, something went wrong.
Same here on both counts. Alphabetical import sorting can be more useful, than for example, new imports being tacked onto the end:
|
Sorry, something went wrong.
But as a contributor to various projects, each of which expects or enforces a slightly different code style (and most of which expect me to format the code), I get the opposite of consistency. If alphabetical import sorting is useful, I do think it should be preferred for new code across the entire project. Then, it would be easier to accept that in some parts of the code we enforce some parts of the style guide. It worries me to see a maintainer that has things set up just right, slightly differently than what's in the docs, while others get an inscrutable error for what should be a simple contribution. Should we be worried about non-dogfooded devguide instructions? |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
📚 Documentation preview 📚: https://cpython-previews--122018.org.readthedocs.build/