mypy: Enable truthy-bool errors.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-05-31 16:31:28 -07:00 committed by Tim Abbott
parent 74e94ae78c
commit df69e1d979
7 changed files with 13 additions and 19 deletions

View File

@ -4706,7 +4706,7 @@ class InvoiceTest(StripeTestCase):
def test_invoice_plan_without_stripe_customer(self) -> None: def test_invoice_plan_without_stripe_customer(self) -> None:
self.local_upgrade(self.seat_count, True, CustomerPlan.ANNUAL, False, False) self.local_upgrade(self.seat_count, True, CustomerPlan.ANNUAL, False, False)
plan = get_current_plan_by_realm(get_realm("zulip")) 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.stripe_customer_id = None
plan.customer.save(update_fields=["stripe_customer_id"]) plan.customer.save(update_fields=["stripe_customer_id"])
with self.assertRaises(BillingError) as context: with self.assertRaises(BillingError) as context:

View File

@ -27,6 +27,7 @@ warn_return_any = false
# Enable optional errors. # Enable optional errors.
enable_error_code = [ enable_error_code = [
"redundant-expr", "redundant-expr",
"truthy-bool",
] ]
# Display the codes needed for # type: ignore[code] annotations. # Display the codes needed for # type: ignore[code] annotations.

View File

@ -1396,7 +1396,7 @@ def check_message(
elif addressee.is_private(): elif addressee.is_private():
user_profiles = addressee.user_profiles() user_profiles = addressee.user_profiles()
mirror_message = client and client.name in [ mirror_message = client.name in [
"zephyr_mirror", "zephyr_mirror",
"irc_mirror", "irc_mirror",
"jabber_mirror", "jabber_mirror",

View File

@ -754,7 +754,6 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase):
iago = self.example_user("iago") iago = self.example_user("iago")
test_bot = self.create_test_bot("foo-bot", iago) test_bot = self.create_test_bot("foo-bot", iago)
self.login_user(iago) self.login_user(iago)
assert test_bot
with queries_captured() as queries: with queries_captured() as queries:
response = self.client_get( response = self.client_get(

View File

@ -644,7 +644,6 @@ class RealmImportExportTest(ExportFile):
realm_emoji = check_add_realm_emoji( realm_emoji = check_add_realm_emoji(
realm=hamlet.realm, name="hawaii", author=hamlet, image_file=img_file realm=hamlet.realm, name="hawaii", author=hamlet, image_file=img_file
) )
assert realm_emoji
self.assertEqual(realm_emoji.name, "hawaii") self.assertEqual(realm_emoji.name, "hawaii")
# Deactivate a user to ensure such a case is covered. # Deactivate a user to ensure such a case is covered.
@ -801,7 +800,7 @@ class RealmImportExportTest(ExportFile):
imported_realm_result = f(imported_realm) imported_realm_result = f(imported_realm)
# orig_realm_result should be truthy and have some values, otherwise # orig_realm_result should be truthy and have some values, otherwise
# the test is kind of meaningless # 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 # It may be helpful to do print(f.__name__) if you are having
# trouble debugging this. # trouble debugging this.

View File

@ -88,8 +88,6 @@ class TransferUploadsToS3Test(ZulipTestCase):
with get_test_image_file("img.png") as image_file: with get_test_image_file("img.png") as image_file:
emoji = check_add_realm_emoji(othello.realm, emoji_name, othello, 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( emoji_path = RealmEmoji.PATH_ID_TEMPLATE.format(
realm_id=othello.realm_id, realm_id=othello.realm_id,
@ -115,8 +113,6 @@ class TransferUploadsToS3Test(ZulipTestCase):
with get_test_image_file("animated_img.gif") as image_file: with get_test_image_file("animated_img.gif") as image_file:
emoji = check_add_realm_emoji(othello.realm, emoji_name, othello, 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( emoji_path = RealmEmoji.PATH_ID_TEMPLATE.format(
realm_id=othello.realm_id, realm_id=othello.realm_id,

View File

@ -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 # 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, # Zulip user mention. We don't know the email, just the Jira username,
# so we naively guess at their Zulip account using this # so we naively guess at their Zulip account using this
if realm: mention_re = re.compile("\\[~(.*?)\\]")
mention_re = re.compile("\\[~(.*?)\\]") for username in mention_re.findall(content):
for username in mention_re.findall(content): # Try to look up username
# Try to look up username user_profile = guess_zulip_user_from_jira(username, realm)
user_profile = guess_zulip_user_from_jira(username, realm) if user_profile:
if user_profile: replacement = f"**{user_profile.full_name}**"
replacement = f"**{user_profile.full_name}**" else:
else: replacement = f"**{username}**"
replacement = f"**{username}**"
content = content.replace(f"[~{username}]", replacement) content = content.replace(f"[~{username}]", replacement)
return content return content