Skip to content
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

style: adopt black #1876

Merged
merged 9 commits into from
Jun 23, 2021
Merged

style: adopt black #1876

merged 9 commits into from
Jun 23, 2021

Conversation

CaselIT
Copy link
Member

@CaselIT CaselIT commented Mar 3, 2021

Just to get the ball rolling.

Tried to run black 20.8b1 21.5b1 with the configuration

[tool.black]
    target-version = ["py35"]
    skip-string-normalization = true
    line-length = 88

The skip-string-normalization avoids the conversion ' to " if we want to keep the current flake8 rules

TODO:

  • re-run with line length 88
  • cleanup string concatenation in the same line (like 'foo bar ' 'baz foobar')
  • review where we need to add / remove tailing commas to improve the styling
  • update the documentation with the changes done to the example folder

Closes #1453

@codecov
Copy link

codecov bot commented Mar 3, 2021

Codecov Report

Merging #1876 (bdddbb4) into master (c550eb3) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1876   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           63        63           
  Lines         6610      6610           
  Branches      1067      1067           
=========================================
  Hits          6610      6610           
Impacted Files Coverage Δ
falcon/__init__.py 100.00% <ø> (ø)
falcon/asgi/structures.py 100.00% <ø> (ø)
falcon/inspect.py 100.00% <ø> (ø)
falcon/media/validators/jsonschema.py 100.00% <ø> (ø)
falcon/responders.py 100.00% <ø> (ø)
falcon/response_helpers.py 100.00% <ø> (ø)
falcon/testing/__init__.py 100.00% <ø> (ø)
falcon/testing/test_case.py 100.00% <ø> (ø)
falcon/util/deprecation.py 100.00% <ø> (ø)
falcon/util/structures.py 100.00% <ø> (ø)
... and 38 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c550eb3...bdddbb4. Read the comment docs.

examples/look/look/images.py Outdated Show resolved Hide resolved
examples/things_advanced.py Outdated Show resolved Hide resolved
@kgriffs
Copy link
Member

kgriffs commented Mar 9, 2021

I am going to delay this for post 3.0 but I do think we should move in this direction. Let's just make sure we have as part of the process a review to tweak the occasional oddity.

@CaselIT
Copy link
Member Author

CaselIT commented Mar 9, 2021

I am going to delay this for post 3.0 but I do think we should move in this direction. Let's just make sure we have as part of the process a review to tweak the occasional oddity.

yes sure, I was not targeting this release, it was just to start looking into it

@CaselIT
Copy link
Member Author

CaselIT commented May 13, 2021

I've updated the change with the latest black.

Regarding the line length it can easily customized. I personally usually use 100, but also black default of 88 is fine. I find 79-80 a bit on the narrow side.

@kgriffs
Copy link
Member

kgriffs commented May 13, 2021

The default of 88 is fine, and avoids excessive line wrapping esp. for deeply nested control structures. If we increased the limit much further I would argue for a separate standard for keeping comments shorter (even if we have to write our own checker for it).

Regardless, I'll take a look through the diff soon and see how things look now.

@CaselIT
Copy link
Member Author

CaselIT commented May 13, 2021

I'll re-reun with the 88 line.

If you are not familiar with black, note that you can tell it to split things in multiple lines by setting a comma at the end.
Like

def foo(x,):
  pass
# becomes
def foo(
  x,
):
  pass

So we may need to add / remove some to get the desired formatting.

https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html?highlight=comma#the-magic-trailing-comma

@vytas7
Copy link
Member

vytas7 commented May 14, 2021

I'm a bit orthodox when it comes to line length, 100+ sounds a bit too long.

But I'm fine with black's 88, it does sound like a good compromise, and... if we're going to use black, we don't need to care about manually keeping lines at 79 or 88 anyway, that's what black is for.

@CaselIT
Copy link
Member Author

CaselIT commented May 14, 2021

Ok, I initially went with 100 both because we do have some lines that are on the long side in the source and it's what I usually use.

I'll re-run with the default 88 and update this.

@CaselIT
Copy link
Member Author

CaselIT commented May 14, 2021

Updated with 88. From the change lines it seems that our average line was a bit longer, since this version adds a 1000 new lines.

For reference the previous with length 100 was more or less a wash regarding line count

Copy link
Member

@kgriffs kgriffs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments inline. I am still favorable to adopting black modulo a few tweaks. Also, note that f we miss any strange formatting issues before merging this, we can always fix those up over time, as we discover them in the course of maintaining the project.

examples/look/look/images.py Outdated Show resolved Hide resolved
examples/look/tests/test_app.py Outdated Show resolved Hide resolved
examples/look/tests/test_app.py Show resolved Hide resolved
falcon/app.py Outdated Show resolved Hide resolved
falcon/media/validators/jsonschema.py Show resolved Hide resolved
@CaselIT
Copy link
Member Author

CaselIT commented May 25, 2021

I'll wait for #1709 before rebasing and polishing this

@CaselIT CaselIT requested a review from kgriffs May 28, 2021 22:01
@CaselIT
Copy link
Member Author

CaselIT commented May 28, 2021

@kgriffs @vytas7 I've updated the docs to use the new formatting, bug I'm not sure I updated all of them.

I've also made a quick pass to the files to check that no funny formatting was added. For this I think we can correct eventual leftover in the future

@@ -85,7 +85,7 @@ filterwarnings =
[flake8]
max-complexity = 15
exclude = .ecosystem,.eggs,.git,.tox,.venv,build,dist,docs,examples,falcon/bench/nuts
ignore = F403,W504
extend-ignore = F403,W504,E203,I202
max-line-length = 99
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we now decrease this to 88?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I guess so

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we have quite a bit of comment/documentation that are over 88 chars

kgriffs
kgriffs previously approved these changes Jun 8, 2021
Copy link
Member

@kgriffs kgriffs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥

Copy link
Member

@vytas7 vytas7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting almost ready 👍

I just had a handful of open questions (commented inline).

And a more general question: should we try updating Cython code for the delimited stream reader etc? When I wrote it, it was loosely based on the Python version, with changes specific to Cython. Right now, that parity would be disturbed a bit. OTOH mangling that code now after the fact is just a (an unnecessary?) risk to introduce regressions.

falcon/routing/compiled.py Outdated Show resolved Hide resolved
falcon/util/uri.py Show resolved Hide resolved
falcon/vendor/mimeparse/mimeparse.py Outdated Show resolved Hide resolved
@CaselIT
Copy link
Member Author

CaselIT commented Jun 14, 2021

And a more general question: should we try updating Cython code for the delimited stream reader etc? When I wrote it, it was loosely based on the Python version, with changes specific to Cython.

black does not support cython, so the formatting would be manual.

Personally I think we could leave it as is or update as needed as a follow on change (maybe in the same issue as the one setting flake line length to 88)

Copy link
Member

@kgriffs kgriffs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@vytas7 vytas7 changed the title style: try running black style: adopt black Jun 23, 2021
Copy link
Member

@vytas7 vytas7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we go then...

@vytas7 vytas7 merged commit 7efb46f into falconry:master Jun 23, 2021
@CaselIT
Copy link
Member Author

CaselIT commented Jun 23, 2021

I've opened #1926 to do the follow up on this change.

Please add there if there were other deferred points from this change. I'll try to get to it this we

@CaselIT CaselIT deleted the try_black branch June 23, 2021 09:00
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 this pull request may close these issues.

Consider using black to normalize coding style
3 participants