Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

python: Remove checks for impossible None.

Anders Kaseorg5ccdbd66e5d4
diff --git a/confirmation/models.py b/confirmation/models.py
index 6be6728c636..80f1381dcc1 100644
--- a/confirmation/models.py
+++ b/confirmation/models.py
@@ -164,7 +164,6 @@ def create_confirmation_object(
if validity_in_minutes is None:
expiry_date = None
else:
- assert validity_in_minutes is not None
expiry_date = current_time + timedelta(minutes=validity_in_minutes)
else:
expiry_date = current_time + timedelta(days=_properties[confirmation_type].validity_in_days)
diff --git a/corporate/lib/activity.py b/corporate/lib/activity.py
index 8310dba764c..17cad906505 100644
--- a/corporate/lib/activity.py
+++ b/corporate/lib/activity.py
@@ -250,7 +250,6 @@ def get_estimated_arr_and_rate_by_realm() -> tuple[dict[str, int], dict[str, str
for plan in plans:
assert plan.customer.realm is not None
latest_ledger_entry = plan.latest_ledger_entry[0]
- assert latest_ledger_entry is not None
renewal_cents = RealmBillingSession(
realm=plan.customer.realm
).get_annual_recurring_revenue_for_support_data(plan, latest_ledger_entry)
@@ -285,10 +284,8 @@ def get_plan_data_by_remote_server() -> dict[int, RemoteActivityPlanData]: # no
server_id = None
assert plan.customer.remote_server is not None
server_id = plan.customer.remote_server.id
- assert server_id is not None
latest_ledger_entry = plan.latest_ledger_entry[0]
- assert latest_ledger_entry is not None
plan_data = get_remote_activity_plan_data(
plan, latest_ledger_entry, remote_server=plan.customer.remote_server
@@ -335,10 +332,8 @@ def get_plan_data_by_remote_realm() -> dict[int, dict[int, RemoteActivityPlanDat
server_id = None
assert plan.customer.remote_realm is not None
server_id = plan.customer.remote_realm.server_id
- assert server_id is not None
latest_ledger_entry = plan.latest_ledger_entry[0]
- assert latest_ledger_entry is not None
plan_data = get_remote_activity_plan_data(
plan, latest_ledger_entry, remote_realm=plan.customer.remote_realm
@@ -351,7 +346,6 @@ def get_plan_data_by_remote_realm() -> dict[int, dict[int, RemoteActivityPlanDat
realm_dict = {realm_id: plan_data}
remote_server_plan_data_by_realm[server_id] = realm_dict
else:
- assert current_server_data is not None
current_realm_data = current_server_data.get(realm_id)
if current_realm_data is not None:
# There should only ever be one CustomerPlan for a remote realm with
diff --git a/corporate/lib/decorator.py b/corporate/lib/decorator.py
index 5b19770a3de..b7f1fa701a7 100644
--- a/corporate/lib/decorator.py
+++ b/corporate/lib/decorator.py
@@ -216,7 +216,6 @@ def authenticated_remote_server_management_endpoint(
return HttpResponseRedirect(url)
- assert remote_billing_user is not None
billing_session = RemoteServerBillingSession(
remote_server, remote_billing_user=remote_billing_user
)
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index de9ad179528..d249a37eb80 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -930,7 +930,6 @@ class BillingSession(ABC):
if days_until_due is not None:
invoice_params["days_until_due"] = days_until_due
stripe_invoice = stripe.Invoice.create(**invoice_params)
- assert stripe_invoice.id is not None
price_args: PriceArgs = {}
if fixed_price is None:
@@ -940,7 +939,6 @@ class BillingSession(ABC):
"unit_amount_decimal": Decimal(price_per_license),
}
else:
- assert fixed_price is not None
amount_due = get_amount_due_fixed_price_plan(fixed_price, billing_schedule)
price_args = {"amount": amount_due}
@@ -1345,7 +1343,6 @@ class BillingSession(ABC):
on_free_trial=on_free_trial,
current_plan_id=current_plan_id,
)
- assert stripe_invoice.id is not None
invoice = Invoice.objects.create(
stripe_invoice_id=stripe_invoice.id,
@@ -1362,7 +1359,6 @@ class BillingSession(ABC):
stripe_invoice = stripe.Invoice.pay(stripe_invoice.id)
except Exception as e:
if stripe_invoice is not None:
- assert stripe_invoice.id is not None
# Void invoice to avoid double charging if customer tries to upgrade again.
stripe.Invoice.void_invoice(stripe_invoice.id)
invoice.status = Invoice.VOID
@@ -1372,7 +1368,6 @@ class BillingSession(ABC):
else: # nocoverage
raise
- assert stripe_invoice.id is not None
return stripe_invoice.id
def create_card_update_session_for_upgrade(
@@ -1896,7 +1891,6 @@ class BillingSession(ABC):
current_plan_id: int | None = None,
) -> str:
customer = self.update_or_create_stripe_customer()
- assert customer is not None # for mypy
fixed_price_plan_offer = get_configured_fixed_price_plan_offer(customer, plan_tier)
general_metadata = {
"billing_modality": billing_modality,
@@ -2252,7 +2246,6 @@ class BillingSession(ABC):
# Send an invoice to the customer which expires at the end of free trial.
# If the customer fails to pay the invoice before expiration, we downgrade
# the customer.
- assert plan is not None
free_trial_days = get_free_trial_days(is_self_hosted_billing)
assert free_trial_days is not None
self.generate_stripe_invoice(
@@ -2270,7 +2263,6 @@ class BillingSession(ABC):
if not stripe_invoice_paid:
# We don't actually expect to ever reach here but this is just a safety net
# in case any future changes make this possible.
- assert plan is not None
self.generate_invoice_for_upgrade(
customer,
price_per_license=price_per_license,
@@ -2996,20 +2988,19 @@ class BillingSession(ABC):
if last_send_invoice is not None:
invoice = stripe.Invoice.retrieve(last_send_invoice.stripe_invoice_id)
- if invoice is not None:
- scheduled_upgrade_invoice_amount_due = format_money(invoice.amount_due)
- pay_by_invoice_payments_page = f"{self.billing_base_url}/invoices"
+ scheduled_upgrade_invoice_amount_due = format_money(invoice.amount_due)
+ pay_by_invoice_payments_page = f"{self.billing_base_url}/invoices"
- if (
- last_send_invoice.plan is not None
- and last_send_invoice.is_created_for_free_trial_upgrade
- ):
- # Automatic payment invoice would have been marked void already.
- assert not last_send_invoice.plan.charge_automatically
- is_free_trial_invoice_expired_notice = True
- free_trial_invoice_expired_notice_page_plan_name = (
- last_send_invoice.plan.name
- )
+ if (
+ last_send_invoice.plan is not None
+ and last_send_invoice.is_created_for_free_trial_upgrade
+ ):
+ # Automatic payment invoice would have been marked void already.
+ assert not last_send_invoice.plan.charge_automatically
+ is_free_trial_invoice_expired_notice = True
+ free_trial_invoice_expired_notice_page_plan_name = (
+ last_send_invoice.plan.name
+ )
annual_price, percent_off_annual_price = get_price_per_license_and_discount(
tier, CustomerPlan.BILLING_SCHEDULE_ANNUAL, customer
@@ -3167,7 +3158,6 @@ class BillingSession(ABC):
voided_invoices_count = 0
for invoice in invoices:
if invoice.status == "open":
- assert invoice.id is not None
stripe.Invoice.void_invoice(invoice.id)
voided_invoices_count += 1
return voided_invoices_count
@@ -3420,7 +3410,6 @@ class BillingSession(ABC):
if not new_tier_plan.automanage_licenses: # nocoverage
licenses_for_new_plan = max(old_plan_licenses_at_next_renewal, licenses_for_new_plan)
- assert licenses_for_new_plan is not None
self.create_license_ledger_entry(
plan=new_tier_plan,
is_renewal=True,
@@ -3463,7 +3452,6 @@ class BillingSession(ABC):
discount = plan.customer.flat_discount * months
plan.customer.flat_discounted_months -= months
plan.customer.save(update_fields=["flat_discounted_months"])
- assert stripe_invoice.id is not None
assert plan.customer.stripe_customer_id is not None
stripe.InvoiceItem.create(
invoice=stripe_invoice.id,
@@ -3483,7 +3471,6 @@ class BillingSession(ABC):
invoice_period: stripe.params.InvoiceItemCreateParamsPeriod,
) -> stripe.params.InvoiceItemCreateParams:
assert plan.customer.stripe_customer_id is not None
- assert stripe_invoice.id is not None
invoice_item_params = stripe.params.InvoiceItemCreateParams(
customer=plan.customer.stripe_customer_id,
currency="usd",
@@ -3511,7 +3498,6 @@ class BillingSession(ABC):
invoice_period: stripe.params.InvoiceItemCreateParamsPeriod,
) -> stripe.params.InvoiceItemCreateParams:
assert plan.customer.stripe_customer_id is not None
- assert stripe_invoice.id is not None
invoice_item_params = stripe.params.InvoiceItemCreateParams(
customer=plan.customer.stripe_customer_id,
currency="usd",
@@ -3622,7 +3608,6 @@ class BillingSession(ABC):
# Ensure we have a stripe.Invoice for the invoice item.
if stripe_invoice is None:
stripe_invoice = self.create_stripe_invoice_for_plan(plan)
- assert stripe_invoice is not None
invoice_period = stripe.params.InvoiceItemCreateParamsPeriod(
start=datetime_to_timestamp(ledger_entry.event_time),
@@ -4018,7 +4003,6 @@ class BillingSession(ABC):
statement_descriptor=stripe_invoice.statement_descriptor,
metadata=stripe_invoice.metadata,
)
- assert new_stripe_invoice.id is not None
invoice_items = stripe_invoice.lines.data
# Stripe does something weird and puts the discount item first, so we need to reverse the order here.
@@ -4054,7 +4038,6 @@ class BillingSession(ABC):
last_sent_invoice.stripe_invoice_id = str(new_stripe_invoice.id)
last_sent_invoice.save(update_fields=["stripe_invoice_id"])
- assert stripe_invoice.id is not None
stripe.Invoice.void_invoice(stripe_invoice.id)
def update_license_ledger_for_manual_plan(
@@ -5920,7 +5903,7 @@ def check_remote_server_audit_log_data(
context = {
"billing_entity": billing_session.billing_entity_display_name,
"support_url": billing_session.support_url(),
- "fixed_price_plan": plan.fixed_price is not None,
+ "fixed_price_plan": True,
"notice_reason": "stale_audit_log_data",
}
if last_audit_log_update is None: # nocoverage
@@ -6054,7 +6037,6 @@ def get_all_invoices_for_customer(customer: Customer) -> Generator[stripe.Invoic
for invoice in invoices:
yield invoice
last_invoice = invoice
- assert last_invoice.id is not None
invoices = stripe.Invoice.list(
customer=customer.stripe_customer_id, starting_after=last_invoice.id, limit=100
)
diff --git a/corporate/lib/stripe_event_handler.py b/corporate/lib/stripe_event_handler.py
index 3a378520f24..11d36d2016e 100644
--- a/corporate/lib/stripe_event_handler.py
+++ b/corporate/lib/stripe_event_handler.py
@@ -173,7 +173,6 @@ def handle_invoice_paid_event(stripe_invoice: stripe.Invoice, invoice: Invoice)
plan_tier = int(metadata["plan_tier"])
charge_automatically = stripe_invoice.collection_method != "send_invoice"
if configured_fixed_price_plan and customer.required_plan_tier == plan_tier:
- assert customer.required_plan_tier is not None
billing_session.process_initial_upgrade(
plan_tier=customer.required_plan_tier,
# TODO: Currently licenses don't play any role for fixed price plan.
diff --git a/corporate/lib/support.py b/corporate/lib/support.py
index 76ab76bd571..be339380dd9 100644
--- a/corporate/lib/support.py
+++ b/corporate/lib/support.py
@@ -336,7 +336,6 @@ def get_plan_data_for_support_view(
plan_data.warning += USER_DATA_STALE_WARNING
plan_data.licenses_used = None
else: # nocoverage
- assert user_count is not None
plan_data.licenses_used = user_count
if plan_data.current_plan.status in (
diff --git a/corporate/tests/test_billing_lib.py b/corporate/tests/test_billing_lib.py
index 91b6650dd3f..8415b5aac36 100644
--- a/corporate/tests/test_billing_lib.py
+++ b/corporate/tests/test_billing_lib.py
@@ -1650,9 +1650,7 @@ class TestSupportBillingHelpers(StripeTestCase):
assert customer.stripe_customer_id is not None
[charge] = iter(stripe.Charge.list(customer=customer.stripe_customer_id))
self.assertEqual(1200 * self.seat_count, charge.amount)
- stripe_customer_id = customer.stripe_customer_id
- assert stripe_customer_id is not None
- [invoice] = iter(stripe.Invoice.list(customer=stripe_customer_id))
+ [invoice] = iter(stripe.Invoice.list(customer=customer.stripe_customer_id))
self.assertEqual(
[1200 * self.seat_count],
[item.amount for item in invoice.lines],
@@ -1675,9 +1673,7 @@ class TestSupportBillingHelpers(StripeTestCase):
)
[charge, _] = iter(stripe.Charge.list(customer=customer.stripe_customer_id))
self.assertEqual(6000 * self.seat_count, charge.amount)
- stripe_customer_id = customer.stripe_customer_id
- assert stripe_customer_id is not None
- [invoice, _] = iter(stripe.Invoice.list(customer=stripe_customer_id))
+ [invoice, _] = iter(stripe.Invoice.list(customer=customer.stripe_customer_id))
self.assertEqual(
[6000 * self.seat_count],
[item.amount for item in invoice.lines],
@@ -1699,9 +1695,7 @@ class TestSupportBillingHelpers(StripeTestCase):
plan.next_invoice_date = self.next_year
plan.save(update_fields=["next_invoice_date"])
invoice_plans_as_needed(self.next_year + timedelta(days=10))
- stripe_customer_id = customer.stripe_customer_id
- assert stripe_customer_id is not None
- [invoice, _, _] = iter(stripe.Invoice.list(customer=stripe_customer_id))
+ [invoice, _, _] = iter(stripe.Invoice.list(customer=customer.stripe_customer_id))
self.assertEqual([4000 * self.seat_count], [item.amount for item in invoice.lines])
realm_audit_log = RealmAuditLog.objects.filter(
event_type=AuditLogEventType.REALM_DISCOUNT_CHANGED
diff --git a/corporate/tests/test_remote_billing.py b/corporate/tests/test_remote_billing.py
index d2b5e840eb7..d26d4568eb2 100644
--- a/corporate/tests/test_remote_billing.py
+++ b/corporate/tests/test_remote_billing.py
@@ -1013,7 +1013,6 @@ class RemoteBillingAuthenticationTest(RemoteRealmBillingTestCase):
# Add server to business plan.
server_billing_session = RemoteServerBillingSession(self.server)
server_customer = server_billing_session.update_or_create_customer(stripe_customer_id=None)
- assert server_customer is not None
# Just create a temporary plan and check if gets transferred or not.
server_plan = CustomerPlan.objects.create(
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index 99640907e4b..0065e2b1364 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -942,7 +942,6 @@ class StripeTest(StripeTestCase):
)
# Customer pays the invoice
- assert invoice.id is not None
stripe.Invoice.pay(invoice.id, paid_out_of_band=True)
self.send_stripe_webhook_events(cursor, "invoice.paid")
@@ -983,7 +982,6 @@ class StripeTest(StripeTestCase):
customer = Customer.objects.get(realm=user.realm)
stripe_customer_id = assert_is_not_none(customer.stripe_customer_id)
[stripe_invoice] = iter(stripe.Invoice.list(customer=stripe_customer_id))
- assert stripe_invoice.id is not None
self.assertEqual(stripe_invoice.status, "open")
invoice = Invoice.objects.get(customer=customer, stripe_invoice_id=stripe_invoice.id)
@@ -1208,7 +1206,6 @@ class StripeTest(StripeTestCase):
cursor = self.pin_event_cursor()
# Customer pays the invoice
- assert invoice.id is not None
stripe.Invoice.pay(invoice.id, paid_out_of_band=True)
self.send_stripe_webhook_events(cursor, "invoice.paid")
@@ -1394,7 +1391,6 @@ class StripeTest(StripeTestCase):
# Customer decides to pay later
cursor = self.pin_event_cursor()
- assert invoice.id is not None
stripe.Invoice.pay(invoice.id, paid_out_of_band=True)
self.send_stripe_webhook_events(cursor, "invoice.paid")
@@ -1679,7 +1675,6 @@ class StripeTest(StripeTestCase):
with self.assertLogs("corporate.stripe", "WARNING"):
self.send_stripe_webhook_events(cursor_before_upgrade)
- assert hamlet_invoice.id is not None
self.assert_details_of_valid_invoice_payment_from_event_status_endpoint(
hamlet_invoice.id,
{
@@ -2216,7 +2211,6 @@ class StripeTest(StripeTestCase):
stripe_customer_id = customer.stripe_customer_id
assert stripe_customer_id is not None
stripe_invoice = stripe.Invoice.create(customer=stripe_customer_id)
- assert stripe_invoice.id is not None
stripe.InvoiceItem.create(
invoice=stripe_invoice.id, amount=5000, currency="usd", customer=stripe_customer_id
)
@@ -2753,7 +2747,6 @@ class StripeTest(StripeTestCase):
self.assertEqual(annual_plan.automanage_licenses, True)
self.assertEqual(annual_plan.billing_schedule, CustomerPlan.BILLING_SCHEDULE_ANNUAL)
- assert self.now is not None
with (
self.assertLogs("corporate.stripe", "INFO") as m,
time_machine.travel(self.now, tick=False),
@@ -3742,7 +3735,6 @@ class StripeTest(StripeTestCase):
days_until_due=30,
statement_descriptor="Zulip Cloud Standard",
)
- assert stripe_invoice.id is not None
stripe.InvoiceItem.create(
invoice=stripe_invoice.id,
currency="usd",
@@ -3762,7 +3754,6 @@ class StripeTest(StripeTestCase):
days_until_due=30,
statement_descriptor="Zulip Cloud Standard",
)
- assert stripe_invoice.id is not None
stripe.InvoiceItem.create(
invoice=stripe_invoice.id,
currency="usd",
@@ -3813,7 +3804,6 @@ class StripeTest(StripeTestCase):
days_until_due=DEFAULT_INVOICE_DAYS_UNTIL_DUE,
statement_descriptor="Zulip Cloud Standard",
)
- assert invoice.id is not None
stripe.InvoiceItem.create(
invoice=invoice.id,
amount=10000,
diff --git a/corporate/tests/test_stripe_remote_realm.py b/corporate/tests/test_stripe_remote_realm.py
index 7312ca8d35a..7e8eb37a728 100644
--- a/corporate/tests/test_stripe_remote_realm.py
+++ b/corporate/tests/test_stripe_remote_realm.py
@@ -1437,7 +1437,6 @@ class TestRemoteRealmBillingFlow(StripeTestCase, RemoteRealmBillingTestCase):
)
zulip_realm_customer = Customer.objects.get(stripe_customer_id=stripe_customer.id)
- assert zulip_realm_customer is not None
realm_complimentary_access_plan = get_current_plan_by_customer(zulip_realm_customer)
assert realm_complimentary_access_plan is not None
self.assertEqual(realm_complimentary_access_plan.tier, CustomerPlan.TIER_SELF_HOSTED_LEGACY)
@@ -1958,7 +1957,6 @@ class TestRemoteRealmBillingFlow(StripeTestCase, RemoteRealmBillingTestCase):
)
zulip_realm_customer = Customer.objects.get(stripe_customer_id=stripe_customer.id)
- assert zulip_realm_customer is not None
realm_complimentary_access_plan = get_current_plan_by_customer(zulip_realm_customer)
assert realm_complimentary_access_plan is not None
self.assertEqual(realm_complimentary_access_plan.tier, CustomerPlan.TIER_SELF_HOSTED_LEGACY)
diff --git a/corporate/tests/test_support_views.py b/corporate/tests/test_support_views.py
index 54439d24af7..b4b98b19a4d 100644
--- a/corporate/tests/test_support_views.py
+++ b/corporate/tests/test_support_views.py
@@ -1570,7 +1570,6 @@ class TestSupportEndpoint(ZulipTestCase):
)
customer = self.create_customer_and_plan(lear_realm, True)
- assert customer is not None
current_plan = get_current_plan_by_customer(customer)
assert current_plan is not None
self.assertIsNone(current_plan.end_date)
diff --git a/corporate/views/support.py b/corporate/views/support.py
index 68c8585a51e..5c757195e7c 100644
--- a/corporate/views/support.py
+++ b/corporate/views/support.py
@@ -884,7 +884,6 @@ def remote_servers_support(
support_type=SupportType.delete_fixed_price_next_plan,
)
elif remote_server_status:
- assert remote_server is not None
remote_server_status_billing_session = RemoteServerBillingSession(
support_staff=acting_user, remote_server=remote_server
)
diff --git a/tools/documentation_crawler/documentation_crawler/commands/crawl_with_status.py b/tools/documentation_crawler/documentation_crawler/commands/crawl_with_status.py
index fcfc8a71c5b..3bd910e0e34 100644
--- a/tools/documentation_crawler/documentation_crawler/commands/crawl_with_status.py
+++ b/tools/documentation_crawler/documentation_crawler/commands/crawl_with_status.py
@@ -21,6 +21,5 @@ class Command(crawl.Command):
self.crawler_process.create_crawler = create_crawler # type: ignore[method-assign] # monkey patching
super().run(args, opts)
for crawler in crawlers:
- assert crawler.stats is not None
if crawler.stats.get_value("log_count/ERROR"):
self.exitcode = 1
diff --git a/zerver/actions/message_send.py b/zerver/actions/message_send.py
index 113b2dbf3a1..b23b2a4372f 100644
--- a/zerver/actions/message_send.py
+++ b/zerver/actions/message_send.py
@@ -1076,8 +1076,6 @@ def do_send_messages(
if send_request.stream is None:
stream_id = send_request.message.recipient.type_id
send_request.stream = Stream.objects.get(id=stream_id)
- # assert needed because stubs for django are missing
- assert send_request.stream is not None
realm_id = send_request.stream.realm_id
sender = send_request.message.sender
@@ -1606,7 +1604,7 @@ def send_pm_if_empty_stream(
"""If a bot sends a message to a stream that doesn't exist or has no
subscribers, sends a notification to the bot owner (if not a
cross-realm bot) so that the owner can correct the issue."""
- if not sender.is_bot or sender.bot_owner is None:
+ if not sender.is_bot:
return
if sender.bot_owner is not None:
diff --git a/zerver/actions/reactions.py b/zerver/actions/reactions.py
index 41aad2b346e..f53b69a2a57 100644
--- a/zerver/actions/reactions.py
+++ b/zerver/actions/reactions.py
@@ -84,7 +84,6 @@ def do_add_reaction(
]:
stream_id = message.recipient.type_id
(stream, sub) = access_stream_by_id(user_profile, stream_id)
- assert stream is not None
if sub:
new_visibility_policy = visibility_policy_for_participation(user_profile, sub.is_muted)
if new_visibility_policy and should_change_visibility_policy(
diff --git a/zerver/actions/streams.py b/zerver/actions/streams.py
index 8e49b8a01c5..292b2546a99 100644
--- a/zerver/actions/streams.py
+++ b/zerver/actions/streams.py
@@ -1938,7 +1938,6 @@ def do_change_stream_group_based_setting(
)
send_event_on_commit(stream.realm, event, current_user_ids_with_metadata_access)
- assert acting_user is not None
send_stream_posting_permission_update_notification(
stream,
old_setting_value=old_setting_api_value,
diff --git a/zerver/actions/submessage.py b/zerver/actions/submessage.py
index 3319e00567e..001fecbd67d 100644
--- a/zerver/actions/submessage.py
+++ b/zerver/actions/submessage.py
@@ -68,7 +68,6 @@ def do_add_submessage(
]:
stream_id = submessage.message.recipient.type_id
(stream, sub) = access_stream_by_id(sender, stream_id)
- assert stream is not None
if sub:
new_visibility_policy = visibility_policy_for_participation(sender, sub.is_muted)
if new_visibility_policy and should_change_visibility_policy(
diff --git a/zerver/lib/email_mirror.py b/zerver/lib/email_mirror.py
index 99a32a18489..f36261cc424 100644
--- a/zerver/lib/email_mirror.py
+++ b/zerver/lib/email_mirror.py
@@ -503,7 +503,6 @@ def process_missed_message(to: str, message: EmailMessage) -> None:
body = construct_zulip_body(message, topic_name, user_profile.realm, sender=user_profile)
- assert recipient is not None
if recipient.type == Recipient.STREAM:
stream = get_stream_by_id_in_realm(recipient.type_id, user_profile.realm)
send_mm_reply_to_stream(user_profile, stream, topic_name, body)
diff --git a/zerver/lib/export.py b/zerver/lib/export.py
index 0fc713ea6fd..981518b26cc 100644
--- a/zerver/lib/export.py
+++ b/zerver/lib/export.py
@@ -2282,7 +2282,7 @@ def export_files_from_s3(
email_gateway_bot: UserProfile | None = None
- if handle_system_bots and settings.EMAIL_GATEWAY_BOT is not None:
+ if handle_system_bots:
internal_realm = get_realm(settings.SYSTEM_BOT_REALM)
email_gateway_bot = get_system_bot(settings.EMAIL_GATEWAY_BOT, internal_realm.id)
user_ids.add(email_gateway_bot.id)
diff --git a/zerver/lib/message_cache.py b/zerver/lib/message_cache.py
index 1f9791c0d58..560fc864543 100644
--- a/zerver/lib/message_cache.py
+++ b/zerver/lib/message_cache.py
@@ -450,7 +450,6 @@ class MessageDict:
# TODO: see #1379 to eliminate Markdown dependencies
message = Message.objects.select_related("sender").get(id=message_id)
- assert message is not None # Hint for mypy.
# It's unfortunate that we need to have side effects on the message
# in some cases.
rendered_content = save_message_rendered_content(message, content)
diff --git a/zerver/lib/narrow.py b/zerver/lib/narrow.py
index 07807ccd491..ea4751bce87 100644
--- a/zerver/lib/narrow.py
+++ b/zerver/lib/narrow.py
@@ -124,8 +124,7 @@ class NarrowParameter(BaseModel):
try:
self.operand = operand_validator("operand", self.operand)
self.operator = check_string("operator", self.operator)
- if self.negated is not None:
- self.negated = check_bool("negated", self.negated)
+ self.negated = check_bool("negated", self.negated)
except ValidationError as error:
raise JsonableError(error.message)
diff --git a/zerver/lib/scim.py b/zerver/lib/scim.py
index bfb64da6674..215933ea36e 100644
--- a/zerver/lib/scim.py
+++ b/zerver/lib/scim.py
@@ -586,7 +586,6 @@ class ZulipSCIMGroup(SCIMGroup):
def save(self) -> None:
realm = self.realm
- assert realm is not None
if not check_can_manage_group_by_scim(self.obj):
raise scim_exceptions.BadRequestError(
diff --git a/zerver/lib/send_email.py b/zerver/lib/send_email.py
index ee85b5a514d..2badb023afe 100644
--- a/zerver/lib/send_email.py
+++ b/zerver/lib/send_email.py
@@ -239,8 +239,7 @@ def build_email(
mail = EmailMultiAlternatives(
email_subject, message, envelope_from, to_emails, reply_to=reply_to, headers=extra_headers
)
- if html_message is not None:
- mail.attach_alternative(html_message, "text/html")
+ mail.attach_alternative(html_message, "text/html")
return mail
diff --git a/zerver/lib/sessions.py b/zerver/lib/sessions.py
index 2b0611d3eaf..d11323d3b44 100644
--- a/zerver/lib/sessions.py
+++ b/zerver/lib/sessions.py
@@ -30,7 +30,6 @@ def get_session_dict_user(session_dict: Mapping[str, int]) -> int | None:
# Compare django.contrib.auth._get_user_session_key
try:
pk = get_user_model()._meta.pk
- assert pk is not None
return pk.to_python(session_dict[SESSION_KEY])
except KeyError:
return None
diff --git a/zerver/lib/stream_subscription.py b/zerver/lib/stream_subscription.py
index 728aceabe10..e0a38b825e3 100644
--- a/zerver/lib/stream_subscription.py
+++ b/zerver/lib/stream_subscription.py
@@ -104,7 +104,6 @@ def get_used_colors_for_user_ids(user_ids: list[int]) -> dict[int, set[str]]:
result: dict[int, set[str]] = defaultdict(set)
for row in query:
- assert row["color"] is not None
result[row["user_profile_id"]].add(row["color"])
return result
diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py
index 8e3d1780546..7376065aa92 100644
--- a/zerver/lib/streams.py
+++ b/zerver/lib/streams.py
@@ -565,9 +565,7 @@ def is_user_in_can_administer_channel_group(
# Important: The caller must have verified the acting user is not
# a guest, to enforce that can_administer_channel_group has
# allow_everyone_group=False.
- group_allowed_to_administer_channel_id = stream.can_administer_channel_group_id
- assert group_allowed_to_administer_channel_id is not None
- return group_allowed_to_administer_channel_id in user_recursive_group_ids
+ return stream.can_administer_channel_group_id in user_recursive_group_ids
def is_user_in_can_add_subscribers_group(
@@ -576,9 +574,7 @@ def is_user_in_can_add_subscribers_group(
# Important: The caller must have verified the acting user is not
# a guest, to enforce that can_add_subscribers_group has
# allow_everyone_group=False.
- group_allowed_to_add_subscribers_id = stream.can_add_subscribers_group_id
- assert group_allowed_to_add_subscribers_id is not None
- return group_allowed_to_add_subscribers_id in user_recursive_group_ids
+ return stream.can_add_subscribers_group_id in user_recursive_group_ids
def is_user_in_can_subscribe_group(stream: Stream, user_recursive_group_ids: set[int]) -> bool:
@@ -606,9 +602,7 @@ def is_user_in_can_remove_subscribers_group(
# Important: The caller must have verified the acting user is not
# a guest, to enforce that can_remove_subscribers_group has
# allow_everyone_group=False.
- group_allowed_to_remove_subscribers_id = stream.can_remove_subscribers_group_id
- assert group_allowed_to_remove_subscribers_id is not None
- return group_allowed_to_remove_subscribers_id in user_recursive_group_ids
+ return stream.can_remove_subscribers_group_id in user_recursive_group_ids
def check_stream_access_based_on_can_send_message_group(
@@ -1461,10 +1455,8 @@ def get_streams_to_which_user_cannot_add_subscribers(
def can_administer_accessible_channel(channel: Stream, user_profile: UserProfile) -> bool:
# IMPORTANT: This function expects its callers to have already
# checked that the user can access the provided channel.
- group_id_allowed_to_administer_channel = channel.can_administer_channel_group_id
- assert group_id_allowed_to_administer_channel is not None
return user_has_permission_for_group_setting(
- group_id_allowed_to_administer_channel,
+ channel.can_administer_channel_group_id,
user_profile,
Stream.stream_permission_group_settings["can_administer_channel_group"],
)
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
index 755f52a536a..e22f9baa790 100644
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -765,7 +765,6 @@ Output:
"""Helper for parsing page_params after fetching the web app's home view."""
doc = lxml.html.document_fromstring(result.content)
div = doc.get_element_by_id("page-params")
- assert div is not None
page_params_json = div.get("data-params")
assert page_params_json is not None
page_params = orjson.loads(page_params_json)
diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py
index fbae56d46b6..656e3986205 100644
--- a/zerver/lib/test_helpers.py
+++ b/zerver/lib/test_helpers.py
@@ -611,11 +611,9 @@ def load_subdomain_token(response: Union["TestHttpResponse", HttpResponse]) -> E
match = resolve(urlsplit(response["Location"]).path)
assert match.func == log_into_subdomain
token = match.kwargs["token"]
- data = ExternalAuthResult(
+ return ExternalAuthResult(
request=mock.MagicMock(), login_token=token, delete_stored_data=False
).data_dict
- assert data is not None
- return data
P = ParamSpec("P")
diff --git a/zerver/lib/thumbnail.py b/zerver/lib/thumbnail.py
index a1b5df36c18..c2b16ed00c6 100644
--- a/zerver/lib/thumbnail.py
+++ b/zerver/lib/thumbnail.py
@@ -605,7 +605,6 @@ def process_inline_images_to_thumbnails(
if inline_image_div is not None:
inline_image_div.decompose()
else:
- assert placeholder_image_tag is not None
placeholder_image_tag.decompose()
return True, None
diff --git a/zerver/lib/upload/__init__.py b/zerver/lib/upload/__init__.py
index a1eb5939adc..692fa0cf56a 100644
--- a/zerver/lib/upload/__init__.py
+++ b/zerver/lib/upload/__init__.py
@@ -669,13 +669,9 @@ def handle_reupload_emojis_event(realm: Realm, logger: logging.Logger) -> None:
emoji_bytes_io = io.BytesIO(emoji_file_content)
- user_profile = realm_emoji.author
- # When this runs, emojis have already been migrated to always have .author set.
- assert user_profile is not None
-
logger.info("Reuploading emoji %s", realm_emoji.id)
realm_emoji.is_animated = upload_emoji_image(
- emoji_bytes_io, emoji_filename, user_profile, content_type
+ emoji_bytes_io, emoji_filename, realm_emoji.author, content_type
)
realm_emoji.save(update_fields=["is_animated"])
diff --git a/zerver/lib/user_status.py b/zerver/lib/user_status.py
index f5f4a67137c..7aa06f69e54 100644
--- a/zerver/lib/user_status.py
+++ b/zerver/lib/user_status.py
@@ -188,7 +188,6 @@ def check_update_user_status(
# If we're asking to set an emoji (not clear it ("") or not adjust
# it (None)), we need to verify the emoji is valid.
if emoji_name not in ["", None]:
- assert emoji_name is not None
assert emoji_code is not None
assert emoji_type is not None
check_emoji_request(realm, emoji_name, emoji_code, emoji_type)
diff --git a/zerver/lib/users.py b/zerver/lib/users.py
index 9a60aadfe44..b24fcd0e6c3 100644
--- a/zerver/lib/users.py
+++ b/zerver/lib/users.py
@@ -531,10 +531,7 @@ def validate_user_custom_profile_field(
return validator(var_name, value)
elif field_type == CustomProfileField.DROPDOWN:
choice_field_validator = CustomProfileField.DROPDOWN_FIELD_VALIDATORS[field_type]
- field_data = field.field_data
- # Put an assertion so that mypy doesn't complain.
- assert field_data is not None
- return choice_field_validator(var_name, field_data, value)
+ return choice_field_validator(var_name, field.field_data, value)
elif field_type == CustomProfileField.USER:
user_field_validator = CustomProfileField.USER_FIELD_VALIDATORS[field_type]
return user_field_validator(realm_id, value, False)
diff --git a/zerver/management/commands/unarchive_channel.py b/zerver/management/commands/unarchive_channel.py
index 48186369788..7bfccae599b 100644
--- a/zerver/management/commands/unarchive_channel.py
+++ b/zerver/management/commands/unarchive_channel.py
@@ -99,5 +99,4 @@ class Command(ZulipBaseCommand):
f"Channel with name '{new_name}' already exists; pass a different --new-name"
)
- assert channel is not None
do_unarchive_stream(channel, new_name, acting_user=None)
diff --git a/zerver/middleware.py b/zerver/middleware.py
index c23cac63cb7..0ae5c13d6cd 100644
--- a/zerver/middleware.py
+++ b/zerver/middleware.py
@@ -494,7 +494,6 @@ class LocaleMiddleware(DjangoLocaleMiddleware):
i18n_patterns_used, _ = is_language_prefix_patterns_used(urlconf)
if not (i18n_patterns_used and language_from_path):
patch_vary_headers(response, ("Accept-Language",))
- assert language is not None
response.setdefault("Content-Language", language)
# An additional responsibility of our override of this middleware is to save the user's language
diff --git a/zerver/migrations/0041_create_attachments_for_old_messages.py b/zerver/migrations/0041_create_attachments_for_old_messages.py
index 838a21be8f4..d41adaaea24 100644
--- a/zerver/migrations/0041_create_attachments_for_old_messages.py
+++ b/zerver/migrations/0041_create_attachments_for_old_messages.py
@@ -31,15 +31,14 @@ def check_and_create_attachments(apps: StateApps, schema_editor: BaseDatabaseSch
not stream.invite_only and stream.realm.domain != "mit.edu"
)
- if path_id is not None:
- attachment = Attachment.objects.create(
- file_name=os.path.basename(path_id),
- path_id=path_id,
- owner=user_profile,
- realm=user_profile.realm,
- is_realm_public=is_message_realm_public,
- )
- attachment.messages.add(message)
+ attachment = Attachment.objects.create(
+ file_name=os.path.basename(path_id),
+ path_id=path_id,
+ owner=user_profile,
+ realm=user_profile.realm,
+ is_realm_public=is_message_realm_public,
+ )
+ attachment.messages.add(message)
class Migration(migrations.Migration):
diff --git a/zerver/models/users.py b/zerver/models/users.py
index 004cdc32097..d329ce390f7 100644
--- a/zerver/models/users.py
+++ b/zerver/models/users.py
@@ -1124,7 +1124,6 @@ def get_active_user_profile_by_id_in_realm(uid: int, realm: "Realm") -> UserProf
def get_user_including_cross_realm(email: str, realm: "Realm") -> UserProfile:
if is_cross_realm_bot_email(email):
return get_system_bot(email, realm.id)
- assert realm is not None
return get_user(email, realm)
diff --git a/zerver/openapi/openapi.py b/zerver/openapi/openapi.py
index 96ddddb288e..6c347392ada 100644
--- a/zerver/openapi/openapi.py
+++ b/zerver/openapi/openapi.py
@@ -460,7 +460,6 @@ def validate_test_response(request: Request, response: Response) -> bool:
path = request.path.removeprefix("/api/v1")
else:
return False
- assert request.method is not None
method = request.method.lower()
status_code = str(response.status_code)
@@ -580,7 +579,6 @@ def validate_test_request(
status_code: str,
intentionally_undocumented: bool = False,
) -> None:
- assert request.method is not None
method = request.method.lower()
if request.path.startswith("/json/"):
url = request.path.removeprefix("/json")
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py
index 68f03e87a77..325e1ccdf56 100644
--- a/zerver/tests/test_auth_backends.py
+++ b/zerver/tests/test_auth_backends.py
@@ -413,7 +413,6 @@ class AuthBackendTest(ZulipTestCase):
result = self.client_get("/login/", {"preview": "true"})
self.assertEqual(result.status_code, 200)
self.assert_in_response(realm.description, result)
- assert realm.name is not None
self.assert_in_response(realm.name, result)
self.assert_in_response("Log in to Zulip", result)
diff --git a/zerver/tests/test_channel_fetch.py b/zerver/tests/test_channel_fetch.py
index ba394ce8dae..e463f473245 100644
--- a/zerver/tests/test_channel_fetch.py
+++ b/zerver/tests/test_channel_fetch.py
@@ -47,7 +47,6 @@ class GetStreamsTest(ZulipTestCase):
def test_streams_api_for_bot_owners(self) -> None:
hamlet = self.example_user("hamlet")
test_bot = self.create_test_bot("foo", hamlet)
- assert test_bot is not None
realm = get_realm("zulip")
self.login_user(hamlet)
diff --git a/zerver/tests/test_create_video_call.py b/zerver/tests/test_create_video_call.py
index a554b32cc1a..844ba9e01ee 100644
--- a/zerver/tests/test_create_video_call.py
+++ b/zerver/tests/test_create_video_call.py
@@ -100,7 +100,6 @@ class ZoomVideoCallTestUserAuth(ZulipTestCase):
responses.calls[-1].request.url,
"https://api.zoom.us/v2/users/me/meetings",
)
- assert responses.calls[-1].request.body is not None
self.assertEqual(
orjson.loads(responses.calls[-1].request.body),
{
diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py
index 73e2429393f..1ee86124d95 100644
--- a/zerver/tests/test_docs.py
+++ b/zerver/tests/test_docs.py
@@ -617,7 +617,6 @@ class CustomShorthandLinksTest(ZulipTestCase):
class IntegrationTest(ZulipTestCase):
def test_check_if_every_integration_has_logo_that_exists(self) -> None:
for integration in INTEGRATIONS.values():
- assert integration.logo_url is not None
path = urlsplit(integration.logo_url).path
self.assertTrue(os.path.isfile(settings.DEPLOY_ROOT + path), integration.name)
diff --git a/zerver/tests/test_embedded_bot_system.py b/zerver/tests/test_embedded_bot_system.py
index 891bd09d0fb..37c339e61c4 100644
--- a/zerver/tests/test_embedded_bot_system.py
+++ b/zerver/tests/test_embedded_bot_system.py
@@ -39,8 +39,6 @@ class TestEmbeddedBotMessaging(ZulipTestCase):
)
def test_pm_to_embedded_bot_using_direct_group_message(self) -> None:
- assert self.bot_profile is not None
-
direct_group_message = get_or_create_direct_message_group(
id_list=[self.user_profile.id, self.bot_profile.id]
)
@@ -59,7 +57,6 @@ class TestEmbeddedBotMessaging(ZulipTestCase):
self.assertEqual(display_recipient[1]["email"], self.bot_profile.email)
def test_stream_message_to_embedded_bot(self) -> None:
- assert self.bot_profile is not None
self.send_stream_message(
self.user_profile,
"Denmark",
@@ -78,7 +75,6 @@ class TestEmbeddedBotMessaging(ZulipTestCase):
self.assertEqual(last_message.content, "foo")
def test_message_to_embedded_bot_with_initialize(self) -> None:
- assert self.bot_profile is not None
self.subscribe(self.user_profile, "Denmark")
with patch(
"zulip_bots.bots.helloworld.helloworld.HelloWorldHandler.initialize", create=True
@@ -92,7 +88,6 @@ class TestEmbeddedBotMessaging(ZulipTestCase):
mock_initialize.assert_called_once()
def test_embedded_bot_quit_exception(self) -> None:
- assert self.bot_profile is not None
with (
patch(
"zulip_bots.bots.helloworld.helloworld.HelloWorldHandler.handle_message",
diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py
index fe831b7b05d..f8a70d0f4cd 100644
--- a/zerver/tests/test_import_export.py
+++ b/zerver/tests/test_import_export.py
@@ -1749,7 +1749,6 @@ class RealmImportExportTest(ExportFile):
image_file=img_file,
content_type="image/png",
)
- assert new_realm_emoji is not None
original_realm_emoji_count = RealmEmoji.objects.count()
self.assertGreaterEqual(original_realm_emoji_count, 2)
new_realm_emoji.author = hamlet
@@ -3141,7 +3140,6 @@ class RealmImportExportTest(ExportFile):
self.assertIn(emoji_id, imported_realm_emoji_dict)
realm_emoji_info = imported_realm_emoji_dict[emoji_id]
self.assertEqual(emoji_id, realm_emoji_info["id"])
- assert imported_realm_emoji.author is not None
assert isinstance(imported_realm_emoji.author.id, int)
assert isinstance(realm_emoji_info["author_id"], int)
self.assertEqual(imported_realm_emoji.author.id, int(realm_emoji_info["author_id"]))
diff --git a/zerver/tests/test_invite.py b/zerver/tests/test_invite.py
index b212c67d856..b1ef4332cac 100644
--- a/zerver/tests/test_invite.py
+++ b/zerver/tests/test_invite.py
@@ -669,7 +669,7 @@ class InviteUserTest(InviteUserBase):
self.assert_json_success(result)
prereg_user = PreregistrationUser.objects.get(email=mirror_user.email)
- assert prereg_user.referred_by is not None and inviter is not None
+ assert prereg_user.referred_by is not None
self.assertEqual(
prereg_user.referred_by.email,
inviter.email,
diff --git a/zerver/tests/test_push_registration.py b/zerver/tests/test_push_registration.py
index c04c64f62fb..598f6c3d15d 100644
--- a/zerver/tests/test_push_registration.py
+++ b/zerver/tests/test_push_registration.py
@@ -785,7 +785,6 @@ class RegisterPushDeviceToServer(BouncerTestCase):
result = self.client_post("/json/mobile_push/register", rotate_push_key_payload)
self.assert_json_success(result)
device.refresh_from_db()
- assert device.push_key is not None
assert type(rotate_push_key_payload["push_key"]) is str # for mypy
self.assertEqual(
bytes(device.push_key), check_push_key(rotate_push_key_payload["push_key"])
diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py
index bf85a6b5733..5e69711dc28 100644
--- a/zerver/tests/test_realm.py
+++ b/zerver/tests/test_realm.py
@@ -1000,7 +1000,6 @@ class RealmTest(ZulipTestCase):
realm.save(update_fields=["signup_announcements_stream"])
signup_announcements_stream = realm.signup_announcements_stream
- assert signup_announcements_stream is not None
self.assertEqual(signup_announcements_stream, verona)
do_deactivate_stream(signup_announcements_stream, acting_user=None)
realm.refresh_from_db()
@@ -1075,7 +1074,6 @@ class RealmTest(ZulipTestCase):
realm.save(update_fields=["zulip_update_announcements_stream"])
zulip_update_announcements_stream = realm.zulip_update_announcements_stream
- assert zulip_update_announcements_stream is not None
self.assertEqual(zulip_update_announcements_stream, verona)
do_deactivate_stream(zulip_update_announcements_stream, acting_user=None)
realm.refresh_from_db()
@@ -1143,7 +1141,6 @@ class RealmTest(ZulipTestCase):
realm.save(update_fields=["moderation_request_channel"])
moderation_request_channel = realm.moderation_request_channel
- assert moderation_request_channel is not None
self.assertEqual(moderation_request_channel, verona)
do_deactivate_stream(moderation_request_channel, acting_user=None)
realm.refresh_from_db()
diff --git a/zerver/tests/test_realm_emoji.py b/zerver/tests/test_realm_emoji.py
index 881d1f1a7e8..7725a6e5199 100644
--- a/zerver/tests/test_realm_emoji.py
+++ b/zerver/tests/test_realm_emoji.py
@@ -28,8 +28,6 @@ class RealmEmojiTest(ZulipTestCase):
image_file=img_file,
content_type="image/png",
)
- if realm_emoji is None:
- raise Exception("Error creating test emoji.") # nocoverage
return realm_emoji
def test_list(self) -> None:
@@ -69,7 +67,6 @@ class RealmEmojiTest(ZulipTestCase):
self.assert_json_success(result)
self.assertEqual(200, result.status_code)
realm_emoji = RealmEmoji.objects.get(name="my_emoji")
- assert realm_emoji.author is not None
self.assertEqual(realm_emoji.author.email, email)
result = self.client_get("/json/realm/emoji")
@@ -100,7 +97,6 @@ class RealmEmojiTest(ZulipTestCase):
self.assert_json_success(result)
self.assertEqual(200, result.status_code)
realm_emoji = RealmEmoji.objects.get(name="smile")
- assert realm_emoji.author is not None
self.assertEqual(realm_emoji.author.email, email)
def test_realm_emoji_repr(self) -> None:
diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.py
index ea59d6ccbbc..b63b91a298d 100644
--- a/zerver/tests/test_slack_importer.py
+++ b/zerver/tests/test_slack_importer.py
@@ -3829,7 +3829,6 @@ To Do
realm_id,
)
- assert emoji_result.filename is not None
self.assertFalse(emoji_result.filename.startswith(emoji_name))
self.assertRegex(emoji_result.filename, r"^[a-f0-9]{8}\.\w+$")
self.assertTrue(
@@ -3907,7 +3906,6 @@ To Do
logs.output,
)
- assert emoji_result.filename is not None
self.assertFalse(emoji_result.filename.startswith(emoji_name))
self.assertRegex(emoji_result.filename, r"^[a-f0-9]{8}\.\w+$")
self.assertTrue(emoji_result.filename.endswith(".gif"))
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py
index eb6cb71fcda..b523cb580d9 100644
--- a/zerver/tests/test_subs.py
+++ b/zerver/tests/test_subs.py
@@ -280,7 +280,6 @@ class StreamAdminTest(ZulipTestCase):
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
modified_stream=stream,
).order_by("-id")[1]
- assert invite_only_log is not None
expected_extra_data = {
RealmAuditLog.OLD_VALUE: True,
@@ -370,7 +369,6 @@ class StreamAdminTest(ZulipTestCase):
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
modified_stream=stream,
).order_by("-id")[1]
- assert invite_only_log is not None
expected_extra_data = {
RealmAuditLog.OLD_VALUE: False,
diff --git a/zerver/tests/test_upload_local.py b/zerver/tests/test_upload_local.py
index 5f8e19d3561..f1667b0e3d9 100644
--- a/zerver/tests/test_upload_local.py
+++ b/zerver/tests/test_upload_local.py
@@ -302,7 +302,6 @@ class LocalStorageTest(UploadSerializeMixin, ZulipTestCase):
user_profile = self.example_user("iago")
self.assertTrue(user_profile.is_realm_admin)
- assert settings.TEST_WORKER_DIR is not None
tarball_path = os.path.join(settings.TEST_WORKER_DIR, "tarball.tar.gz")
with open(tarball_path, "w") as f:
f.write("dummy")
diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py
index cb109788723..0d06ea94aa5 100644
--- a/zerver/tests/test_users.py
+++ b/zerver/tests/test_users.py
@@ -2433,7 +2433,7 @@ class ActivateTest(ZulipTestCase):
ScheduledEmail.objects.filter(users__in=[hamlet, iago]).distinct().count(), 1
)
email = ScheduledEmail.objects.all().first()
- assert email is not None and email.users is not None
+ assert email is not None
self.assertEqual(email.users.count(), 2)
def test_clear_schedule_emails(self) -> None:
diff --git a/zerver/tests/test_zilencer_analytics.py b/zerver/tests/test_zilencer_analytics.py
index 11ab8dcf03e..6aa7a9081f7 100644
--- a/zerver/tests/test_zilencer_analytics.py
+++ b/zerver/tests/test_zilencer_analytics.py
@@ -217,7 +217,6 @@ class AnalyticsBouncerTest(BouncerTestCase):
self.add_mock_response()
# Send any existing data over, so that we can start the test with a "clean" slate
remote_server = self.server
- assert remote_server is not None
self.assertIsNone(remote_server.last_version)
send_server_data_to_push_bouncer()
@@ -1369,7 +1368,6 @@ class AnalyticsBouncerTest(BouncerTestCase):
# Hard-delete a realm to test the non existent realm uuid case.
zephyr_realm = get_realm("zephyr")
- assert zephyr_realm is not None
deleted_realm_uuid = zephyr_realm.uuid
zephyr_realm.delete()
diff --git a/zerver/views/message_fetch.py b/zerver/views/message_fetch.py
index c14c42317d6..6a5a356f1ac 100644
--- a/zerver/views/message_fetch.py
+++ b/zerver/views/message_fetch.py
@@ -186,11 +186,8 @@ def get_messages_backend(
else:
assert isinstance(maybe_user_profile, UserProfile)
user_profile = maybe_user_profile
- assert user_profile is not None
is_web_public_query = False
- assert realm is not None
-
if is_web_public_query:
# client_gravatar here is just the user-requested value. "finalize_payload" function
# is responsible for sending avatar_url based on each individual sender's
diff --git a/zerver/views/registration.py b/zerver/views/registration.py
index c05bc57934e..69106f0b678 100644
--- a/zerver/views/registration.py
+++ b/zerver/views/registration.py
@@ -1605,7 +1605,6 @@ def create_demo_helper(
how_realm_creator_found_zulip=how_realm_creator_found_zulip,
how_realm_creator_found_zulip_extra_context=how_realm_creator_found_zulip_extra_context,
)
- assert realm is not None
user_default_language = get_default_language_for_new_user(realm, request=request)
with override_language(user_default_language):
diff --git a/zerver/views/streams.py b/zerver/views/streams.py
index 519bf46aa0e..1c11c65062d 100644
--- a/zerver/views/streams.py
+++ b/zerver/views/streams.py
@@ -1187,7 +1187,6 @@ def get_topics_backend(
is_web_public_query = False
assert isinstance(maybe_user_profile, UserProfile)
user_profile = maybe_user_profile
- assert user_profile is not None
if is_web_public_query:
realm = get_valid_realm_from_request(request)
diff --git a/zerver/views/upload.py b/zerver/views/upload.py
index eafe8895ae1..adcbe10c38a 100644
--- a/zerver/views/upload.py
+++ b/zerver/views/upload.py
@@ -124,8 +124,6 @@ def serve_s3(
# get the _unescaped_ new internal request URL in nginx.
parsed_url = urlsplit(url)
assert parsed_url.hostname is not None
- assert parsed_url.path is not None
- assert parsed_url.query is not None
escaped_path_parts = parsed_url.hostname + quote(parsed_url.path) + "?" + parsed_url.query
response = internal_nginx_redirect("/internal/s3/" + escaped_path_parts)
diff --git a/zerver/views/users.py b/zerver/views/users.py
index 1a1a2c7397e..19ba3005748 100644
--- a/zerver/views/users.py
+++ b/zerver/views/users.py
@@ -405,7 +405,6 @@ def avatar_by_id(
except UserProfile.DoesNotExist:
url = get_avatar_for_inaccessible_user()
- assert url is not None
if request.META["QUERY_STRING"]:
url = append_url_query_string(url, request.META["QUERY_STRING"])
return redirect(url)
@@ -442,7 +441,6 @@ def avatar_by_email(
avatar_version = 1
url = get_gravatar_url(email, avatar_version, realm.id, medium)
- assert url is not None
if request.META["QUERY_STRING"]:
url = append_url_query_string(url, request.META["QUERY_STRING"])
return redirect(url)
@@ -557,7 +555,6 @@ def patch_bot_backend(
if service_payload_url is not None:
check_valid_interface_type(service_interface)
- assert service_interface is not None
do_update_outgoing_webhook_service(
bot,
interface=service_interface,
diff --git a/zerver/webhooks/jira/view.py b/zerver/webhooks/jira/view.py
index 63ef6f63840..4fd0bea273b 100644
--- a/zerver/webhooks/jira/view.py
+++ b/zerver/webhooks/jira/view.py
@@ -358,8 +358,7 @@ def api_jira_webhook(
if event is None:
raise AnomalousWebhookPayloadError
- if event is not None:
- content_func = JIRA_CONTENT_FUNCTION_MAPPER.get(event)
+ content_func = JIRA_CONTENT_FUNCTION_MAPPER.get(event)
if content_func is None:
raise UnsupportedWebhookEventTypeError(event)
diff --git a/zilencer/models.py b/zilencer/models.py
index 80c646ee8b7..de0033ad233 100644
--- a/zilencer/models.py
+++ b/zilencer/models.py
@@ -614,7 +614,6 @@ def get_remote_realm_guest_and_non_guest_count(
)
if latest_audit_log is not None:
- assert latest_audit_log is not None
user_count = get_remote_customer_user_count([latest_audit_log])
else:
user_count = RemoteCustomerUserCount(guest_user_count=0, non_guest_user_count=0)
diff --git a/zproject/backends.py b/zproject/backends.py
index 1ecdc04d5f8..50c5d30b4df 100644
--- a/zproject/backends.py
+++ b/zproject/backends.py
@@ -1698,8 +1698,6 @@ def sync_user_from_ldap(user_profile: UserProfile, logger: logging.Logger) -> bo
return False
ldap_user = ZulipLDAPUser(backend, ldap_username, realm=user_profile.realm)
- assert ldap_user is not None
-
# What one would expect to see like to do here is just a call to
# `backend.populate_user`, which in turn just creates the
# `_LDAPUser` object and calls `ldap_user.populate_user()` on