diff --git a/tools/custom_check.py b/tools/custom_check.py index 9a93fa41..9a094c9a 100644 --- a/tools/custom_check.py +++ b/tools/custom_check.py @@ -36,17 +36,6 @@ python_rules = RuleList( "good_lines": ["def foo (self):"], "bad_lines": ["def foo(self: Any):"], }, - # This next check could have false positives, but it seems pretty - # rare; if we find any, they can be added to the exclude list for - # this rule. - { - "pattern": r" % [a-zA-Z0-9_.]*\)?$", - "description": "Used % comprehension without a tuple", - }, - { - "pattern": r".*%s.* % \([a-zA-Z0-9_.]*\)$", - "description": "Used % comprehension without a tuple", - }, { "pattern": r"__future__", "include_only": {"zulip_bots/zulip_bots/bots/"}, diff --git a/tools/provision b/tools/provision index e261d612..fea26490 100755 --- a/tools/provision +++ b/tools/provision @@ -43,7 +43,7 @@ the Python version this command is executed with.""" py_version = tuple(int(num) for num in py_version_list[0:2]) venv_name = f"zulip-api-py{py_version[0]}-venv" - if py_version <= (3, 1) and (not options.force): + if py_version <= (3, 1) and not options.force: print( red + "Provision failed: Cannot create venv with outdated Python version ({}).\n" diff --git a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py index 185711bd..c3c534d6 100644 --- a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py +++ b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py @@ -75,7 +75,7 @@ class IRCBot(irc.bot.SingleServerIRCBot): in_the_specified_stream = msg["display_recipient"] == self.stream at_the_specified_subject = msg["subject"].casefold() == self.topic.casefold() if in_the_specified_stream and at_the_specified_subject: - msg["content"] = ("@**{}**: ".format(msg["sender_full_name"])) + msg["content"] + msg["content"] = "@**{}**: ".format(msg["sender_full_name"]) + msg["content"] send = lambda x: self.c.privmsg(self.channel, x) else: return diff --git a/zulip/integrations/google/google-calendar b/zulip/integrations/google/google-calendar index 227a42ae..85906bd4 100755 --- a/zulip/integrations/google/google-calendar +++ b/zulip/integrations/google/google-calendar @@ -82,7 +82,7 @@ parser.add_argument( options = parser.parse_args() -if not (options.zulip_email): +if not options.zulip_email: parser.error("You must specify --user") zulip_client = zulip.init_from_options(options) diff --git a/zulip/integrations/rss/rss-bot b/zulip/integrations/rss/rss-bot index 96e3d24f..fd0db73d 100755 --- a/zulip/integrations/rss/rss-bot +++ b/zulip/integrations/rss/rss-bot @@ -227,7 +227,7 @@ for feed_url in feed_urls: ) if ( entry_time is not None - and (time.time() - calendar.timegm(entry_time)) > OLDNESS_THRESHOLD * 60 * 60 * 24 + and time.time() - calendar.timegm(entry_time) > OLDNESS_THRESHOLD * 60 * 60 * 24 ): # As a safeguard against misbehaving feeds, don't try to process # entries older than some threshold. @@ -235,7 +235,7 @@ for feed_url in feed_urls: if entry_hash in old_feed_hashes: # We've already seen this. No need to process any older entries. break - if (not old_feed_hashes) and (len(new_hashes) >= 3): + if not old_feed_hashes and len(new_hashes) >= 3: # On a first run, pick up the 3 most recent entries. An RSS feed has # entries in reverse chronological order. break diff --git a/zulip/integrations/trello/zulip_trello.py b/zulip/integrations/trello/zulip_trello.py index 08aeadd7..9e290c0d 100755 --- a/zulip/integrations/trello/zulip_trello.py +++ b/zulip/integrations/trello/zulip_trello.py @@ -122,7 +122,7 @@ at . parser.add_argument( "--trello-board-id", required=True, - help=("The Trello board short ID. Can usually be found in the URL of the Trello board."), + help="The Trello board short ID. Can usually be found in the URL of the Trello board.", ) parser.add_argument( "--trello-api-key", diff --git a/zulip/integrations/zephyr/zephyr_mirror_backend.py b/zulip/integrations/zephyr/zephyr_mirror_backend.py index 0d9f228e..6282e628 100755 --- a/zulip/integrations/zephyr/zephyr_mirror_backend.py +++ b/zulip/integrations/zephyr/zephyr_mirror_backend.py @@ -474,7 +474,7 @@ def process_notice( # Drop messages not to the listed subscriptions if is_personal and not options.forward_personals: return - if (zephyr_class.lower() not in current_zephyr_subs) and not is_personal: + if zephyr_class.lower() not in current_zephyr_subs and not is_personal: logger.debug("Skipping ... %s/%s/%s", zephyr_class, zephyr_instance, is_personal) return if notice.z_default_format.startswith(b"Zephyr error: See") or notice.z_default_format.endswith( @@ -916,7 +916,7 @@ def maybe_forward_to_zephyr(message: Dict[str, Any], zulip_client: zulip.Client) # The key string can be used to direct any type of text. if message["sender_email"] == zulip_account_email: if not ( - (message["type"] == "stream") + message["type"] == "stream" or ( message["type"] == "private" and False diff --git a/zulip/zulip/cli.py b/zulip/zulip/cli.py index 170460b6..16d4f958 100755 --- a/zulip/zulip/cli.py +++ b/zulip/zulip/cli.py @@ -60,7 +60,7 @@ def send_message(recipients: List[str], stream: str, subject: str, message: str) if len(recipients) != 0 and has_stream: click.echo("You cannot specify both a username and a stream/subject.") raise SystemExit(1) - if len(recipients) == 0 and (has_stream != has_subject): + if len(recipients) == 0 and has_stream != has_subject: click.echo("Stream messages must have a subject") raise SystemExit(1) if len(recipients) == 0 and not has_stream: diff --git a/zulip/zulip/send.py b/zulip/zulip/send.py index 09b00432..f58f80fd 100755 --- a/zulip/zulip/send.py +++ b/zulip/zulip/send.py @@ -77,7 +77,7 @@ def main() -> int: # Sanity check user data if len(options.recipients) != 0 and (options.stream or options.subject): parser.error("You cannot specify both a username and a stream/subject.") - if len(options.recipients) == 0 and (bool(options.stream) != bool(options.subject)): + if len(options.recipients) == 0 and bool(options.stream) != bool(options.subject): parser.error("Stream messages must have a subject") if len(options.recipients) == 0 and not (options.stream and options.subject): parser.error("You must specify a stream/subject or at least one recipient.") diff --git a/zulip_bots/zulip_bots/bots/chessbot/chessbot.py b/zulip_bots/zulip_bots/bots/chessbot/chessbot.py index 2c81db14..f1970d98 100644 --- a/zulip_bots/zulip_bots/bots/chessbot/chessbot.py +++ b/zulip_bots/zulip_bots/bots/chessbot/chessbot.py @@ -401,7 +401,7 @@ def make_loss_response(board: chess.Board, reason: str) -> str: Returns: The loss response string. """ - return ("*{}* {}. **{}** wins!\n\n{}").format( + return "*{}* {}. **{}** wins!\n\n{}".format( "White" if board.turn else "Black", reason, "Black" if board.turn else "White", @@ -418,7 +418,7 @@ def make_not_legal_response(board: chess.Board, move_san: str) -> str: Returns: The not-legal-move response string. """ - return ("Sorry, the move *{}* isn't legal.\n\n{}\n\n\n{}").format( + return "Sorry, the move *{}* isn't legal.\n\n{}\n\n\n{}".format( move_san, make_str(board, board.turn), make_footer() ) diff --git a/zulip_bots/zulip_bots/bots/converter/converter.py b/zulip_bots/zulip_bots/bots/converter/converter.py index c23a6b9d..56cb392a 100644 --- a/zulip_bots/zulip_bots/bots/converter/converter.py +++ b/zulip_bots/zulip_bots/bots/converter/converter.py @@ -62,10 +62,10 @@ def get_bot_converter_response(message: Dict[str, str], bot_handler: BotHandler) results = [] for convert_index in convert_indexes: - if (convert_index + 1) < len(words) and words[convert_index + 1] == "help": + if convert_index + 1 < len(words) and words[convert_index + 1] == "help": results.append(utils.HELP_MESSAGE) continue - if (convert_index + 3) < len(words): + if convert_index + 3 < len(words): number = words[convert_index + 1] unit_from = utils.ALIASES.get(words[convert_index + 2], words[convert_index + 2]) unit_to = utils.ALIASES.get(words[convert_index + 3], words[convert_index + 3]) @@ -132,7 +132,7 @@ def get_bot_converter_response(message: Dict[str, str], bot_handler: BotHandler) new_content = "" for idx, result in enumerate(results, 1): - new_content += ((str(idx) + ". conversion: ") if len(results) > 1 else "") + result + "\n" + new_content += (str(idx) + ". conversion: " if len(results) > 1 else "") + result + "\n" return new_content diff --git a/zulip_bots/zulip_bots/bots/game_of_fifteen/game_of_fifteen.py b/zulip_bots/zulip_bots/bots/game_of_fifteen/game_of_fifteen.py index 4a4ae50a..db26fa53 100644 --- a/zulip_bots/zulip_bots/bots/game_of_fifteen/game_of_fifteen.py +++ b/zulip_bots/zulip_bots/bots/game_of_fifteen/game_of_fifteen.py @@ -62,16 +62,16 @@ class GameOfFifteenModel: if tile not in coordinates: raise BadMoveError("You can only move tiles which exist in the board.") i, j = coordinates[tile] - if (j - 1) > -1 and board[i][j - 1] == 0: + if j - 1 > -1 and board[i][j - 1] == 0: board[i][j - 1] = tile board[i][j] = 0 - elif (i - 1) > -1 and board[i - 1][j] == 0: + elif i - 1 > -1 and board[i - 1][j] == 0: board[i - 1][j] = tile board[i][j] = 0 - elif (j + 1) < 3 and board[i][j + 1] == 0: + elif j + 1 < 3 and board[i][j + 1] == 0: board[i][j + 1] = tile board[i][j] = 0 - elif (i + 1) < 3 and board[i + 1][j] == 0: + elif i + 1 < 3 and board[i + 1][j] == 0: board[i + 1][j] = tile board[i][j] = 0 else: diff --git a/zulip_bots/zulip_bots/bots/incident/incident.py b/zulip_bots/zulip_bots/bots/incident/incident.py index 9bfa3fca..59a24764 100644 --- a/zulip_bots/zulip_bots/bots/incident/incident.py +++ b/zulip_bots/zulip_bots/bots/incident/incident.py @@ -85,7 +85,7 @@ def generate_ticket_id(storage: Any) -> str: except KeyError: incident_num = 0 incident_num += 1 - incident_num = incident_num % (1000) + incident_num = incident_num % 1000 storage.put("ticket_id", incident_num) ticket_id = "TICKET%04d" % (incident_num,) return ticket_id diff --git a/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py b/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py index bafae6f5..4c296a63 100644 --- a/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py +++ b/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py @@ -64,7 +64,7 @@ class LinkShortenerHandler: shortened_links = [self.shorten_link(link) for link in link_matches] link_pairs = [ - (link_match + ": " + shortened_link) + link_match + ": " + shortened_link for link_match, shortened_link in zip(link_matches, shortened_links) if shortened_link != "" ] diff --git a/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py b/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py index 20ecb55c..d80fd5ac 100644 --- a/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py +++ b/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py @@ -152,7 +152,7 @@ def is_legal_move(v1, h1, v2, h2, turn, phase, grid): return ( is_in_grid(v2, h2) and is_empty(v2, h2, grid) - and (not is_jump(v1, h1, v2, h2)) + and not is_jump(v1, h1, v2, h2) and is_own_piece(v1, h1, turn, grid) ) diff --git a/zulip_bots/zulip_bots/bots/merels/merels.py b/zulip_bots/zulip_bots/bots/merels/merels.py index e15d4474..6d2e9c0e 100644 --- a/zulip_bots/zulip_bots/bots/merels/merels.py +++ b/zulip_bots/zulip_bots/bots/merels/merels.py @@ -34,8 +34,7 @@ class MerelsModel: data = game_data.GameData(merels.get_game_data(self.topic)) return data.get_phase() > 1 and ( - (mechanics.get_piece("X", data.grid()) <= 2) - or (mechanics.get_piece("O", data.grid()) <= 2) + mechanics.get_piece("X", data.grid()) <= 2 or mechanics.get_piece("O", data.grid()) <= 2 ) def make_move(self, move: str, player_number: int, computer_move: bool = False) -> Any: diff --git a/zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py b/zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py index abc54f13..da8370f1 100644 --- a/zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py +++ b/zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py @@ -194,8 +194,8 @@ class TicTacToeModel: move_coords = move_coords_str.split(",") # Subtraction must be done to convert to the right indices, # since computers start numbering at 0. - row = (int(move_coords[1])) - 1 - column = (int(move_coords[0])) - 1 + row = int(move_coords[1]) - 1 + column = int(move_coords[0]) - 1 if board[row][column] != 0: raise BadMoveError("Make sure your space hasn't already been filled.") board[row][column] = player_number + 1 diff --git a/zulip_bots/zulip_bots/bots/trello/test_trello.py b/zulip_bots/zulip_bots/bots/trello/test_trello.py index a53ea67d..f5f10397 100644 --- a/zulip_bots/zulip_bots/bots/trello/test_trello.py +++ b/zulip_bots/zulip_bots/bots/trello/test_trello.py @@ -83,7 +83,7 @@ class TestTrelloBot(BotTestCase, DefaultTests): with self.mock_http_conversation("get_lists"): self.verify_reply( "get-all-lists TEST", - ("**Lists:**\n1. TEST_A\n * TEST_1\n2. TEST_B\n * TEST_2"), + "**Lists:**\n1. TEST_A\n * TEST_1\n2. TEST_B\n * TEST_2", ) def test_command_exceptions(self) -> None: diff --git a/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py b/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py index 2f134909..8704ec41 100644 --- a/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py +++ b/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py @@ -134,7 +134,7 @@ def generate_quiz_id(storage: Any) -> str: except (KeyError, TypeError): quiz_num = 0 quiz_num += 1 - quiz_num = quiz_num % (1000) + quiz_num = quiz_num % 1000 storage.put("quiz_id", quiz_num) quiz_id = "Q%03d" % (quiz_num,) return quiz_id diff --git a/zulip_bots/zulip_bots/bots/weather/weather.py b/zulip_bots/zulip_bots/bots/weather/weather.py index 46540fac..3ad572aa 100644 --- a/zulip_bots/zulip_bots/bots/weather/weather.py +++ b/zulip_bots/zulip_bots/bots/weather/weather.py @@ -40,7 +40,7 @@ class WeatherHandler: @**Weather Bot** Portland, Me """.strip() - if (message["content"] == "help") or (message["content"] == ""): + if message["content"] == "help" or message["content"] == "": response = help_content else: api_params = dict(q=message["content"], APPID=self.api_key) diff --git a/zulip_bots/zulip_bots/bots/yoda/yoda.py b/zulip_bots/zulip_bots/bots/yoda/yoda.py index 4ae410a7..826a7fad 100644 --- a/zulip_bots/zulip_bots/bots/yoda/yoda.py +++ b/zulip_bots/zulip_bots/bots/yoda/yoda.py @@ -92,7 +92,7 @@ class YodaSpeakHandler: def handle_input(self, message: Dict[str, str], bot_handler: BotHandler) -> None: original_content = message["content"] - if self.is_help(original_content) or (original_content == ""): + if self.is_help(original_content) or original_content == "": bot_handler.send_reply(message, HELP_MESSAGE) else: