From df69e1d9792a5ea7a72e32981f68a46a7fb88ce1 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 31 May 2022 16:31:28 -0700 Subject: [PATCH] mypy: Enable truthy-bool errors. Signed-off-by: Anders Kaseorg --- corporate/tests/test_stripe.py | 2 +- pyproject.toml | 1 + zerver/actions/message_send.py | 2 +- zerver/tests/test_custom_profile_data.py | 1 - zerver/tests/test_import_export.py | 3 +-- zerver/tests/test_transfer.py | 4 ---- zerver/webhooks/jira/view.py | 19 +++++++++---------- 7 files changed, 13 insertions(+), 19 deletions(-) diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 4a009f0833..f302a62f11 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -4706,7 +4706,7 @@ class InvoiceTest(StripeTestCase): def test_invoice_plan_without_stripe_customer(self) -> None: self.local_upgrade(self.seat_count, True, CustomerPlan.ANNUAL, False, False) plan = get_current_plan_by_realm(get_realm("zulip")) - assert plan and plan.customer + assert plan is not None plan.customer.stripe_customer_id = None plan.customer.save(update_fields=["stripe_customer_id"]) with self.assertRaises(BillingError) as context: diff --git a/pyproject.toml b/pyproject.toml index 92b1b7e275..df83fbf226 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ warn_return_any = false # Enable optional errors. enable_error_code = [ "redundant-expr", + "truthy-bool", ] # Display the codes needed for # type: ignore[code] annotations. diff --git a/zerver/actions/message_send.py b/zerver/actions/message_send.py index 17dccbd51b..19cd1443ce 100644 --- a/zerver/actions/message_send.py +++ b/zerver/actions/message_send.py @@ -1396,7 +1396,7 @@ def check_message( elif addressee.is_private(): user_profiles = addressee.user_profiles() - mirror_message = client and client.name in [ + mirror_message = client.name in [ "zephyr_mirror", "irc_mirror", "jabber_mirror", diff --git a/zerver/tests/test_custom_profile_data.py b/zerver/tests/test_custom_profile_data.py index ac701cbb4a..6932a0bc6b 100644 --- a/zerver/tests/test_custom_profile_data.py +++ b/zerver/tests/test_custom_profile_data.py @@ -754,7 +754,6 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase): iago = self.example_user("iago") test_bot = self.create_test_bot("foo-bot", iago) self.login_user(iago) - assert test_bot with queries_captured() as queries: response = self.client_get( diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py index d4e13a09c6..529de86181 100644 --- a/zerver/tests/test_import_export.py +++ b/zerver/tests/test_import_export.py @@ -644,7 +644,6 @@ class RealmImportExportTest(ExportFile): realm_emoji = check_add_realm_emoji( realm=hamlet.realm, name="hawaii", author=hamlet, image_file=img_file ) - assert realm_emoji self.assertEqual(realm_emoji.name, "hawaii") # Deactivate a user to ensure such a case is covered. @@ -801,7 +800,7 @@ class RealmImportExportTest(ExportFile): imported_realm_result = f(imported_realm) # orig_realm_result should be truthy and have some values, otherwise # the test is kind of meaningless - assert orig_realm_result + assert orig_realm_result # type: ignore[truthy-bool] # see above # It may be helpful to do print(f.__name__) if you are having # trouble debugging this. diff --git a/zerver/tests/test_transfer.py b/zerver/tests/test_transfer.py index 116409fe5d..3188f77255 100644 --- a/zerver/tests/test_transfer.py +++ b/zerver/tests/test_transfer.py @@ -88,8 +88,6 @@ class TransferUploadsToS3Test(ZulipTestCase): with get_test_image_file("img.png") as image_file: emoji = check_add_realm_emoji(othello.realm, emoji_name, othello, image_file) - if not emoji: - raise AssertionError("Unable to add emoji.") emoji_path = RealmEmoji.PATH_ID_TEMPLATE.format( realm_id=othello.realm_id, @@ -115,8 +113,6 @@ class TransferUploadsToS3Test(ZulipTestCase): with get_test_image_file("animated_img.gif") as image_file: emoji = check_add_realm_emoji(othello.realm, emoji_name, othello, image_file) - if not emoji: - raise AssertionError("Unable to add emoji.") emoji_path = RealmEmoji.PATH_ID_TEMPLATE.format( realm_id=othello.realm_id, diff --git a/zerver/webhooks/jira/view.py b/zerver/webhooks/jira/view.py index 442936227d..ac2e23693a 100644 --- a/zerver/webhooks/jira/view.py +++ b/zerver/webhooks/jira/view.py @@ -78,17 +78,16 @@ def convert_jira_markup(content: str, realm: Realm) -> str: # Try to convert a Jira user mention of format [~username] into a # Zulip user mention. We don't know the email, just the Jira username, # so we naively guess at their Zulip account using this - if realm: - mention_re = re.compile("\\[~(.*?)\\]") - for username in mention_re.findall(content): - # Try to look up username - user_profile = guess_zulip_user_from_jira(username, realm) - if user_profile: - replacement = f"**{user_profile.full_name}**" - else: - replacement = f"**{username}**" + mention_re = re.compile("\\[~(.*?)\\]") + for username in mention_re.findall(content): + # Try to look up username + user_profile = guess_zulip_user_from_jira(username, realm) + if user_profile: + replacement = f"**{user_profile.full_name}**" + else: + replacement = f"**{username}**" - content = content.replace(f"[~{username}]", replacement) + content = content.replace(f"[~{username}]", replacement) return content