-
-
Notifications
You must be signed in to change notification settings - Fork 392
Use black and isort for py files. #692
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
Conversation
714260a
to
653ebfd
Compare
b215d3a
to
90af640
Compare
One of the manual pre-fixes we needed to do in the server was for multi-line string literal concatenations that Black moved to the same line. That is the case here too, e.g.: --- a/zulip_bots/zulip_bots/bots/dropbox_share/dropbox_share.py
+++ b/zulip_bots/zulip_bots/bots/dropbox_share/dropbox_share.py
@@ -168,11 +187,11 @@ def dbx_write(client: Any, fn: str, content: str) -> str:
result = client.files_upload(content.encode(), fn)
msg = "Written to file: " + URL.format(name=result.name, path=result.path_lower)
except Exception:
- msg = "Incorrect file path or file already exists.\n"\
- "Usage: `write <filename> CONTENT`"
+ msg = "Incorrect file path or file already exists.\n" "Usage: `write <filename> CONTENT`"
return msg Easiest fix is to write this as a single string literal: msg = "Incorrect file path or file already exists.\nUsage: `write <filename> CONTENT`" You can find these all with $ pylint -d all -e implicit-str-concat $(git ls-files '*.py'; git grep -Pl '\A#!.*\bpython' -- . ':!*.py')
************* Module zulip_bots.bots.dropbox_share.dropbox_share
zulip_bots/zulip_bots/bots/dropbox_share/dropbox_share.py:190:0: W1404: Implicit string concatenation found in assignment (implicit-str-concat)
zulip_bots/zulip_bots/bots/dropbox_share/dropbox_share.py:250:0: W1404: Implicit string concatenation found in assignment (implicit-str-concat)
************* Module zulip_bots.bots.dropbox_share.test_dropbox_share
zulip_bots/zulip_bots/bots/dropbox_share/test_dropbox_share.py:166:0: W1404: Implicit string concatenation found in assignment (implicit-str-concat)
zulip_bots/zulip_bots/bots/dropbox_share/test_dropbox_share.py:230:0: W1404: Implicit string concatenation found in assignment (implicit-str-concat)
************* Module zulip_bots.bots.game_handler_bot.game_handler_bot
zulip_bots/zulip_bots/bots/game_handler_bot/game_handler_bot.py:50:0: W1404: Implicit string concatenation found in assignment (implicit-str-concat)
************* Module zulip_bots.bots.game_of_fifteen.game_of_fifteen
zulip_bots/zulip_bots/bots/game_of_fifteen/game_of_fifteen.py:131:0: W1404: Implicit string concatenation found in assignment (implicit-str-concat)
************* Module libraries.game
zulip_bots/zulip_bots/bots/merels/libraries/game.py:45:0: W1404: Implicit string concatenation found in assignment (implicit-str-concat)
************* Module zulip_bots.bots.twitpost.test_twitpost
zulip_bots/zulip_bots/bots/twitpost/test_twitpost.py:44:0: W1404: Implicit string concatenation found in assignment (implicit-str-concat)
************* Module zulip_bots.bots.yoda.yoda
zulip_bots/zulip_bots/bots/yoda/yoda.py:112:0: W1404: Implicit string concatenation found in assignment (implicit-str-concat) |
I reordered commits and merged the first 4 (which add configuration but don't run lint yet) as the series ending with 4083849. This should make it easier to script moving a PR across the transition. A few notes on things that are a big ugly while skimming the changes, basically all things we had with the server project too:
Overall I'm fine with merging this and fixing forward, since the things where a pre-fix could be helpful feel pretty rare. @andersk I assume you'll do the merge + announcement for how to rebase PRs when you're happy with the pre-fixing story, since you generated those instructions last time. |
87f6b9b
to
a26f5a5
Compare
I tried to use |
We uses `pyupgrade --py3-plus` to automatically replace all occurence of `Text`. But manual fix is required to remove the unused imports. Note that with this configuration pyupgrade also convert string literals to .format(...) style, which is manually not included in the commit as well.
This includes mainly fixes of string literals using f-strings or .format(...), as well as unpacking of list comprehensions.
@PIG208 Thanks for working on this! This PR looks pretty good overall! Before reviewing the whole PR, just skimming it made me want to mention a couple of things:
The only concern I have with merging this as-is is that it makes it harder to go back and take a deeper look at some of the edge cases that require manual intervention and were missed by the automated migration of string formatting styles. A more modular set of PRs would allow us to avoid having files that use f-style strings but are also riddled with calls to Let me know what you all think, thanks! :) |
I guess we can split the pyupgrade related things to another PR and deprioritize them at the moment. Maybe it will be much better (and much easier) for us to work on that if we can get the black and isort related changes merged first.
Yes, I think this might be a good direction. |
@PIG208 Yes, I agree with getting the bulk of the black and isort changes merged. After that, we can inspect the string formatting migration changes more closely. A quick check I would do is to do a |
I'm not sure about backing out the pyupgrade changes; let me take a look and see if I'd be happier just merging this as this PR plans. Also, I don't want to split the Black migration to multiple PRs, because that'll make instructions for rebasing harder. |
Yeah, after reviewing this, I think merging this as-is makes sense. Huge thanks for all the work on this @PIG208! Can you post a chat.zulip.org comment similar to https://chat.zulip.org/#narrow/stream/2-general/topic/black/near/1117538 for how to rebase across the isort+Black changes without manually resolving merge conflicts? I think we should open a few follow-up workstreams:
|
I have posted the instruction on chat.zulip.org. However, probably because some of the manual fixes aren't separated into different commits, the script I wrote cannot ideally eliminate all the diffs brought by this PR. |
Yeah, I think that's OK -- we don't have many huge open PRs, so most of them are likely to be fairly contained to a small number of files that don't require much manual fixups. |
We add black and isort using the configuration from Zulip and reformat the project.
https://chat.zulip.org/#narrow/stream/127-integrations/topic/black.20and.20isort