-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Use Autoformatting #10606
Comments
Note: #9955 (suggestion of black) |
Note also one of the first lines of PEP 8, that black does not follow in my opinion (though I recognise that's a tradeoff they make). I've used autoformatters in other projects and there are absolutley pros and cons, I have had to manually edit statements to get it to format in a way that makes sense to me. However as you say it makes linting type issues easier. A |
to be clear, black is pep8-compliant. It's code style is a superset of pep8. |
I'm not going to get into philisophical debates (life's too short!), my point was more against autoformatters in general -- consistency for the sake of it is (in my opinion) a bad goal. If you can try YAPF or one of the configurable formatters that would have a very small diff on adoption, perhaps, though in general I'm somewhere between -0 and -0.5. A |
I guess this is a philosophical point indeed- I think consistency for the sake of it is a deeply important goal. The larger the codebase, and the greater the number of contributors, the more valuable this becomes. |
Since I've started working on the testing plugin, I've been a bit frustrated some times due some rules of formatting, especially the 2 blank lines. Since you seem well-versed in all those tools, I'm asking some questions:
|
I am emphatically not an expert in formatting code. I favour autoformatting precisely so that i never have to think about it, know about it, or have long bikeshedding conversations about it!
i'm not sure
you may wish to look at ruff's
is there a reason to have
you'd have to check with @AA-Turner. I think there's one rule that one of the flake8 plugins supports that has not yet been implemented in ruff |
A big reason is that we could move the very very big overloads to those files, and we wouldn't need to bother with the same format considerations (for instance, there are some parts of the code that are typed but where adding overloads for completion would be useful, though it comes at the cost of having a much larger file). |
@picnixz see astral-sh/ruff#8357 seems like |
i'm very sceptical of out-of-source type annotations, but maybe i just need to see a motivating example |
Nah I think that if you are not convinced it's probably an overkill then, nevermind! |
@AA-Turner given #12335 and #12337 I would like to revisit this, and just make a final decision either way 😅 From my understanding, I believe many active maintainers are in favor of this: me, @picnixz, @danieleades, @jayaddison, ...
We have already gone through a round of applying this to smaller sections of the code-base, and working through our understanding of the formatter and how to minimise diffs: |
I'm cautiously in favour of doing this, but perhaps we should delay for a while (a month?) to ensure that any further 7.3.0 issues are tracked down before doing something that could complicate code history trawling? The Also a question that I couldn't find a clear answer to: is there a standard way to annotate package metadata to say what (if any) Python code formatter (incl. version) was used for the code in a distributed package? Probably not at the moment I guess. |
What would be the application for that? |
To be clear, I'm not even saying we format all the code straight away; just to continue along the road of gradually removing files from the |
@danieleades it's a fairly obscure idea, but here it is: some distributions that package Python code include the test suite alongside, so that the distros themselves and/or their users can acceptance-test the contents. However, the source code of a Python package doesn't typically contain any reference (not in the manifest, nor elsewhere) of any linting enforcement applied to the codebase. Linting seems unlikely to currently be in the acceptance criteria for most distributed Python packages, but a suitable metadata entry could enable that possibility. |
I personally have shortcuts for autoformatting now that
would become
and this is ONE thing that I hate because I really want to separate the cases (and for me the first form is much clearer than the second one). So, I use Since we have a CI check that fails if Now, I think it's fine to autoformat files that are already present and yet to be formatted. But I'm not sure how it would be for opened PRs (it usually creates conflicts...). By the way, when I was doing the refactorization of the typing module, the autoformat messed up mypy ignores so it's also not a perfect solution and should be carefully done. |
I feel fairly strongly that this repo should use some sort of pep8-compliant auto-formatter to enforce a common code formatting style.
There are loads of advantages to using an auto-formatter
I don't have any strong feelings about which formatter should be used, or what configuration it should employ. I think the value is in the consistency, not the specific style. I've submitted a few PRs now where i've had to spend 10mins tweaking indents until flake8 is happy. That seems absolutely bonkers to me.
I have personally found
Black
to be really good and have previously suggested it in a rejected PR. I would welcome any other suggestions for a different pep8-compliant formatterThe text was updated successfully, but these errors were encountered: