-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Don't use subscription brackets to break long lines? #951
Comments
I agree that this looks pretty weird. If we can find a way to fix this issue without affecting other existing formatting too much, I'd be supportive of changing it. |
IMO the reason this looks weird is because the line break is on the LHS of an assignment statement and the indented line has a single, trivial expression.
Looks the same kind of weird to me. |
Breaking lines on subscription brackets is quite confusing, it makes it look like list literal (I don't know the better way of formatting this though): return self.client.post(url_for("auth.obtain_token"), json=credentials).json[
"token"
] I think the same formatting can be observed in the following issues - #500 #1048 |
Maybe something like this? return (
self.client.post(url_for("auth.obtain_token"), json=credentials)
.json["token"]
) |
I would even propose : return (
self.client
.post(url_for("auth.obtain_token"), json=credentials)
.json["token"]
) Following the same rule as parameters of a function. If it fits on one line keep it on one line. If not, split in multiline. Here instead of splitting on commas, it splits on dots. |
I found this issue while trying to find community comments on code that I wondered "Is this formatting intentional? Is this a bug? Should I train myself to accept this?" Here is the example I was reviewing: # ...
yield {
# ...
"isAvailable": result["stock"]["relativeInventoryForSets"][
"isAvailable"
],
"appointmentLeadTimeDays": result["stock"][
"appointmentLeadTimeDays"
],
"stockLevel": result["stock"]["stockLevel"],
"zip_code": response.meta["item"]["zip_code"],
} It gets weirder if there's even longer keys to dig into: { # ...
"isAvailable": result["stock"]["relativeInventoryForSets"][
"isAvailable"
]["isLong"]["isQuiteLong"],
} In this specific case, refactoring to a local |
Consider this input:
And output:
I would (subjectively) expect the third assignment to stay the way it was.
Do "a[...]" often contain more than 1 element between the brackets?(Ignore this argument please; of course they do if it's something other than a string literal)Operating system:
Python version: 3.7.3
Black version: 19.3b0
Does also happen on master: yes
The text was updated successfully, but these errors were encountered: