-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Blacken the codebase #8903
Blacken the codebase #8903
Conversation
Ah, this is the one that's probably got things in it I'm actually going to hate. I'm not even going to look at it, as it'll probably annoy me too much. I thought #8902 included this, which is why I was "pleasantly surprised" it was mostly OK. I'm not going to argue against us adopting black, that's a huge debate that I don't have the energy or interest in starting again, so I'll push my head firmly into the sand here. |
Confirmed that the concerns that caused issues w/ trailing commas in #8803, are indeed resolved in this one. |
Uhh... @pypa-bot hasn't reported the NEWS fragment stuff. Oh no. |
Can we do this a module at a time instead? Black is known to not always make the best format decision (sometimes vastly incorrect IMO), and I don’t want the lost context get buried in such a hugh changeset when it does make mistakes. |
Do you want me to make separate commits for each file? |
ddc92c8
to
0e3750f
Compare
"docs/" + kind, | ||
"docs/build/" + kind, | ||
"-c=docs/html", # see note above | ||
f"-d=docs/build/doctrees/{kind}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it me or this feels like a hack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using f-strings feels like a hack? I was going to do this anyway, and black forcing my move to be sooner is OK with me. 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not f-strings, putting two pieces into one item
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I feel that we shouldn't try to fight the tool like this. It's up to black to have a way to allow us to express our intent here, which is to have two arguments, "-c" and "docs/html" which are separate but related. That's the semantics of the command line we'd normally write in the shell, and we should be able to reflect that readably in code.
IMO we just add #fmt: off
to signal that black doesn't do what we want (see here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is exactly what I meant
nox is Python 3.6+, and f-strings are awesome. :)
Okay, GitHub does not like it when there's more than 250 commits. I'mma squash all the tests/data/ commits into a single one. |
9443e6f
to
a96d51d
Compare
Personally, my "unit of review" is the PR, not the commit, so this would not help for me. I'd rather see multiple PRs. I've opted out of getting involved in reviewing the black formatting changes, though, so my opinion isn't relevant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
black is not perfect, but I still think it'll be worth it for us to adopt it, because it's consistent and gives a good output in nearly all cases. In many of the cases, black's "ugly" output is a good indicator of you're doing too much and that's IMO a good thing.
Unsuprisingly, I like it. It is also extremely frustrating when it makes the wrong choices though.
not canonical_package_name or | ||
not link | ||
) | ||
can_not_cache = not self.cache_dir or not canonical_package_name or not link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>.<
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like psf/black#449, so yay!
sdist_dependencies_allowed = ( | ||
options.format_control != binary_only and | ||
not options.ignore_dependencies | ||
options.format_control != binary_only and not options.ignore_dependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>.<
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no way a robot would guess the readability semantics you were after...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which is fine? TBH the point is for it to do a good-enough job. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends on the definition of fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm starting to become a strong supporter of #fmt: off
🙁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, that's fine -- black isn't going to be perfect everywhere. The point is that it's good enough almost all the time and the consistency is very useful.
To me, # fmt: off
is an indication that: I'm sure that this is better than what black did for everyone that'll read the code. This is a great place to use it.
help="Use the order in the given requirements file and its " | ||
"comments when generating output. This option can be " | ||
"used multiple times.") | ||
"comments when generating output. This option can be " | ||
"used multiple times.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh come on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My favorite is when it does ('str 1' 'str2' 'str 3')
and nobody cares
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It no longer does that. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use https://github.com/keisheiled/flake8-implicit-str-concat to find stuff like 'str 1' 'str2' 'str 3'
(None currently found on this branch)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hugovk implicit str concat is not bad if formatted properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@webknjaz flake8-implicit-str-concat only prohibits implicit string concatenation on one line
help="If in a virtualenv that has global access, do not output " | ||
"globally-installed packages.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, okay, this needs to be fixed throughout the codebase actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If by "fixed" you mean "make black not do that" then I agree 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs us to parenthesize all these help assignments, to make them consistent throughout, which is an overall positive change IMO. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer this form but I can see how it could be confusing w/o parentheses.
parts.extend( | ||
[ | ||
user_option_part, | ||
" or ", | ||
permissions_part.lower(), | ||
] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really wouldn't write it like this, but I guess an extra variable doesn't hurt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like psf/black#925, so it'll get fixed down the line?
if dist_path in { | ||
p | ||
for p in {sysconfig.get_path("stdlib"), sysconfig.get_path("platstdlib")} | ||
if p | ||
}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should simplify this by having a variable for the RHS:
paths = {p for p in [sysconfig.get_path("stdlib"), sysconfig.get_path("platstdlib")] if p}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually that whole construct is just opaque IMO. Needs rewriting.
self._discovered_dependencies = defaultdict( | ||
list | ||
) # type: DiscoveredDependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I blame Python 2 (type comments) and over-long variable names for that.
msg = msg + "\n\n" + \ | ||
"To fix this you could try to:\n" + \ | ||
"1. loosen the range of package versions you've specified\n" + \ | ||
"2. remove package versions to allow pip attempt to solve " + \ | ||
"the dependency conflict\n" | ||
msg = ( | ||
msg | ||
+ "\n\n" | ||
+ "To fix this you could try to:\n" | ||
+ "1. loosen the range of package versions you've specified\n" | ||
+ "2. remove package versions to allow pip attempt to solve " | ||
+ "the dependency conflict\n" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably do implicit concat + str.format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or += ? :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because runtime concat would be happening multiple times which is slower + a bunch of implicitly concatenated strings parsed as one literal and then formatted just once...
if isinstance(dist, pkg_resources.DistInfoDistribution) and dist.has_metadata( | ||
metadata_name | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh what?
newpath = initial_slashes + urllib_request.url2pathname(path).replace( | ||
"\\", "/" | ||
).lstrip("/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm... really?
Ah, smart. I think I can do this incrementally too. :)
:) |
Making this PR a draft again, and I'll make a bunch of smaller PRs for adding black in. :) |
Hello! I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the |
Closing since #8543 tracks this. |
Follow up to #8803
Closes #8543
Note to self: how to update this if it stalls