Skip to content

Format code with black #857

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

Closed
sliverc opened this issue Nov 5, 2020 · 5 comments · Fixed by #862
Closed

Format code with black #857

sliverc opened this issue Nov 5, 2020 · 5 comments · Fixed by #862

Comments

@sliverc
Copy link
Member

sliverc commented Nov 5, 2020

Django project proposed to format code with black.

I have been using black in many other projects and had very good experiences with it. As I am currently working on converting tests I very much missed black as a couple of times I had to format code to finally suite flake8 instead of concentrating on coding.

The proposal outlines very well the pros and cons and why Django decided to prose using black.

@sliverc
Copy link
Member Author

sliverc commented Nov 5, 2020

@n2ygk What do you think about this? I have added black configuration to other projects as well so I could follow up with a PR. As this is larger change though I think it is good to get some consensus before i get started.

@n2ygk
Copy link
Contributor

n2ygk commented Nov 5, 2020

I'm OK with complying with whatever the rules are, but I'm personally cringing at: "88 characters per line and double quotes".... Most projects I work on seem to feel comfortable with line length 120. And single quotes don't require holding down the shift key, at least on a US keyboard.

Also it looks like PyCharm's built-in formatting does not yet support Black-style. It was planned for the current release (2020.2) but got removed from that release. You can run black on file save hook but that's not the same as having the IDE implement the style as I type...

So I'm not super-excited but will follow your lead.

@sliverc
Copy link
Member Author

sliverc commented Nov 9, 2020

Thanks for your thoughts.

We should not enforce something which makes working on DJA harder then it should. However before I started to use black I also had some doubts about it and now I miss black any time a project is not using it.

Some thoughts:

  • With black I can just format my code as I type without worrying whether I use double quote, or single quotes whether the line length is too long or linting issues. Black will solve this later on for me. So even with black feel free to continue using single quotes when you write new DJA code.
  • The same counts with pull request reviews - no more discussions about code formatting because black has made those decisions already
  • the line length of 88 is actually not a hard limit very well outlined here.
  • integration into an IDE is nice to have but actually not necessary. What I recommend is we also implement pre-commit so the code actually gets formatted when user commits it to git. So no worry about how IDE formats the code.

Does this makes sense to you?

I am also open to wait a bit more using black in DJA till PyCharm has support for black. Although it doesn't seem like there is any deadline.

@n2ygk
Copy link
Contributor

n2ygk commented Nov 9, 2020

Sure, let's give it a shot and keep the default 88 for now and see how it goes.

pre-commit hook is a good idea.

PyCharm can run black on save so it might be OK. I wonder how that works since PyCharm saves automatically... I guess I can git it a try soon;-)

@sliverc
Copy link
Member Author

sliverc commented Nov 9, 2020

I will see when I get to this. It is easiest though when there are no other PRs open when we do this to avoid merge conflicts.

Current open PRs should be merged soon though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants