Skip to content

Commit 4820238

Browse files
andersktimabbott
authored andcommitted
ruff: Bump target-version from py38 to py310.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 3f29bc4 commit 4820238

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1056
-712
lines changed

analytics/tests/test_counts.py

+30-18
Original file line numberDiff line numberDiff line change
@@ -1432,12 +1432,16 @@ def test_mobile_pushes_received_count(self) -> None:
14321432
"gcm_options": gcm_options,
14331433
}
14341434
now = timezone_now()
1435-
with time_machine.travel(now, tick=False), mock.patch(
1436-
"zilencer.views.send_android_push_notification", return_value=1
1437-
), mock.patch("zilencer.views.send_apple_push_notification", return_value=1), mock.patch(
1438-
"corporate.lib.stripe.RemoteServerBillingSession.current_count_for_billed_licenses",
1439-
return_value=10,
1440-
), self.assertLogs("zilencer.views", level="INFO"):
1435+
with (
1436+
time_machine.travel(now, tick=False),
1437+
mock.patch("zilencer.views.send_android_push_notification", return_value=1),
1438+
mock.patch("zilencer.views.send_apple_push_notification", return_value=1),
1439+
mock.patch(
1440+
"corporate.lib.stripe.RemoteServerBillingSession.current_count_for_billed_licenses",
1441+
return_value=10,
1442+
),
1443+
self.assertLogs("zilencer.views", level="INFO"),
1444+
):
14411445
result = self.uuid_post(
14421446
self.server_uuid,
14431447
"/api/v1/remotes/push/notify",
@@ -1491,12 +1495,16 @@ def test_mobile_pushes_received_count(self) -> None:
14911495
"apns_payload": apns_payload,
14921496
"gcm_options": gcm_options,
14931497
}
1494-
with time_machine.travel(now, tick=False), mock.patch(
1495-
"zilencer.views.send_android_push_notification", return_value=1
1496-
), mock.patch("zilencer.views.send_apple_push_notification", return_value=1), mock.patch(
1497-
"corporate.lib.stripe.RemoteServerBillingSession.current_count_for_billed_licenses",
1498-
return_value=10,
1499-
), self.assertLogs("zilencer.views", level="INFO"):
1498+
with (
1499+
time_machine.travel(now, tick=False),
1500+
mock.patch("zilencer.views.send_android_push_notification", return_value=1),
1501+
mock.patch("zilencer.views.send_apple_push_notification", return_value=1),
1502+
mock.patch(
1503+
"corporate.lib.stripe.RemoteServerBillingSession.current_count_for_billed_licenses",
1504+
return_value=10,
1505+
),
1506+
self.assertLogs("zilencer.views", level="INFO"),
1507+
):
15001508
result = self.uuid_post(
15011509
self.server_uuid,
15021510
"/api/v1/remotes/push/notify",
@@ -1549,12 +1557,16 @@ def test_mobile_pushes_received_count(self) -> None:
15491557
realm_date_created=realm.date_created,
15501558
)
15511559

1552-
with time_machine.travel(now, tick=False), mock.patch(
1553-
"zilencer.views.send_android_push_notification", return_value=1
1554-
), mock.patch("zilencer.views.send_apple_push_notification", return_value=1), mock.patch(
1555-
"corporate.lib.stripe.RemoteRealmBillingSession.current_count_for_billed_licenses",
1556-
return_value=10,
1557-
), self.assertLogs("zilencer.views", level="INFO"):
1560+
with (
1561+
time_machine.travel(now, tick=False),
1562+
mock.patch("zilencer.views.send_android_push_notification", return_value=1),
1563+
mock.patch("zilencer.views.send_apple_push_notification", return_value=1),
1564+
mock.patch(
1565+
"corporate.lib.stripe.RemoteRealmBillingSession.current_count_for_billed_licenses",
1566+
return_value=10,
1567+
),
1568+
self.assertLogs("zilencer.views", level="INFO"),
1569+
):
15581570
result = self.uuid_post(
15591571
self.server_uuid,
15601572
"/api/v1/remotes/push/notify",

corporate/lib/stripe_event_handler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def handle_checkout_session_completed_event(
112112
session.customer, stripe_session.metadata.get("user_id")
113113
)
114114
payment_method = stripe_setup_intent.payment_method
115-
assert isinstance(payment_method, (str, type(None)))
115+
assert isinstance(payment_method, (str, type(None))) # noqa: UP038 # https://github.com/python/mypy/issues/17413
116116

117117
if session.type in [
118118
Session.CARD_UPDATE_FROM_BILLING_PAGE,

corporate/tests/test_remote_billing.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,10 @@ class RemoteBillingAuthenticationTest(RemoteRealmBillingTestCase):
283283
def test_self_hosted_config_error_page(self) -> None:
284284
self.login("desdemona")
285285

286-
with self.settings(
287-
CORPORATE_ENABLED=False, PUSH_NOTIFICATION_BOUNCER_URL=None
288-
), self.assertLogs("django.request"):
286+
with (
287+
self.settings(CORPORATE_ENABLED=False, PUSH_NOTIFICATION_BOUNCER_URL=None),
288+
self.assertLogs("django.request"),
289+
):
289290
result = self.client_get("/self-hosted-billing/not-configured/")
290291
self.assertEqual(result.status_code, 500)
291292
self.assert_in_response(
@@ -703,9 +704,10 @@ def test_remote_billing_authentication_flow_generate_two_confirmation_links_befo
703704
# Now click the second confirmation link. The RemoteRealmBillingUser entry
704705
# stays the same, since it's already been created, and the user is redirected
705706
# normally further through the flow, while we log this event.
706-
with time_machine.travel(now + timedelta(seconds=1), tick=False), self.assertLogs(
707-
"corporate.stripe", "INFO"
708-
) as mock_logger:
707+
with (
708+
time_machine.travel(now + timedelta(seconds=1), tick=False),
709+
self.assertLogs("corporate.stripe", "INFO") as mock_logger,
710+
):
709711
result = self.client_get(second_confirmation_url, subdomain="selfhosting")
710712
self.assertEqual(result.status_code, 302)
711713
self.assertTrue(result["Location"].startswith("/remote-billing-login/"))

corporate/tests/test_stripe.py

+45-29
Original file line numberDiff line numberDiff line change
@@ -2253,10 +2253,13 @@ def test_upgrade_with_uncaught_exception(self, *mock_args: Any) -> None:
22532253
hamlet = self.example_user("hamlet")
22542254
self.login_user(hamlet)
22552255
self.add_card_to_customer_for_upgrade()
2256-
with patch(
2257-
"corporate.lib.stripe.BillingSession.create_stripe_invoice_and_charge",
2258-
side_effect=Exception,
2259-
), self.assertLogs("corporate.stripe", "WARNING") as m:
2256+
with (
2257+
patch(
2258+
"corporate.lib.stripe.BillingSession.create_stripe_invoice_and_charge",
2259+
side_effect=Exception,
2260+
),
2261+
self.assertLogs("corporate.stripe", "WARNING") as m,
2262+
):
22602263
response = self.upgrade(talk_to_stripe=False)
22612264
self.assertIn("ERROR:corporate.stripe:Uncaught exception in billing", m.output[0])
22622265
self.assertIn(m.records[0].stack_info, m.output[0])
@@ -2273,9 +2276,12 @@ def test_invoice_payment_succeeded_event_with_uncaught_exception(self, *mock_arg
22732276
self.login_user(hamlet)
22742277
self.add_card_to_customer_for_upgrade()
22752278

2276-
with patch(
2277-
"corporate.lib.stripe.BillingSession.process_initial_upgrade", side_effect=Exception
2278-
), self.assertLogs("corporate.stripe", "WARNING"):
2279+
with (
2280+
patch(
2281+
"corporate.lib.stripe.BillingSession.process_initial_upgrade", side_effect=Exception
2282+
),
2283+
self.assertLogs("corporate.stripe", "WARNING"),
2284+
):
22792285
response = self.upgrade()
22802286

22812287
response_dict = self.assert_json_success(response)
@@ -2609,9 +2615,10 @@ def test_redirect_for_billing_page_downgrade_at_free_trial_end(self, *mocks: Moc
26092615
self.assert_in_response(substring, response)
26102616

26112617
# schedule downgrade
2612-
with time_machine.travel(self.now + timedelta(days=3), tick=False), self.assertLogs(
2613-
"corporate.stripe", "INFO"
2614-
) as m:
2618+
with (
2619+
time_machine.travel(self.now + timedelta(days=3), tick=False),
2620+
self.assertLogs("corporate.stripe", "INFO") as m,
2621+
):
26152622
response = self.client_billing_patch(
26162623
"/billing/plan",
26172624
{"status": CustomerPlan.DOWNGRADE_AT_END_OF_FREE_TRIAL},
@@ -3927,9 +3934,10 @@ def test_reupgrade_by_billing_admin_after_downgrade(self) -> None:
39273934
expected_log = f"INFO:corporate.stripe:Change plan status: Customer.id: {stripe_customer_id}, CustomerPlan.id: {new_plan.id}, status: {CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE}"
39283935
self.assertEqual(m.output[0], expected_log)
39293936

3930-
with self.assertRaises(BillingError) as context, self.assertLogs(
3931-
"corporate.stripe", "WARNING"
3932-
) as m:
3937+
with (
3938+
self.assertRaises(BillingError) as context,
3939+
self.assertLogs("corporate.stripe", "WARNING") as m,
3940+
):
39333941
with time_machine.travel(self.now, tick=False):
39343942
self.local_upgrade(
39353943
self.seat_count, True, CustomerPlan.BILLING_SCHEDULE_ANNUAL, True, False
@@ -7010,9 +7018,10 @@ def test_redirect_for_remote_realm_billing_page_downgrade_at_free_trial_end(
70107018
self.assert_in_response(substring, response)
70117019

70127020
# schedule downgrade
7013-
with time_machine.travel(self.now + timedelta(days=3), tick=False), self.assertLogs(
7014-
"corporate.stripe", "INFO"
7015-
) as m:
7021+
with (
7022+
time_machine.travel(self.now + timedelta(days=3), tick=False),
7023+
self.assertLogs("corporate.stripe", "INFO") as m,
7024+
):
70167025
response = self.client_billing_patch(
70177026
"/billing/plan",
70187027
{"status": CustomerPlan.DOWNGRADE_AT_END_OF_FREE_TRIAL},
@@ -7400,8 +7409,9 @@ def test_upgrade_user_to_fixed_price_plan_pay_by_invoice(self, *mocks: Mock) ->
74007409
self.execute_remote_billing_authentication_flow(hamlet)
74017410
mock_invoice = MagicMock()
74027411
mock_invoice.hosted_invoice_url = "payments_page_url"
7403-
with time_machine.travel(self.now, tick=False), mock.patch(
7404-
"stripe.Invoice.retrieve", return_value=mock_invoice
7412+
with (
7413+
time_machine.travel(self.now, tick=False),
7414+
mock.patch("stripe.Invoice.retrieve", return_value=mock_invoice),
74057415
):
74067416
result = self.client_get(
74077417
f"{self.billing_session.billing_base_url}/upgrade/?tier={CustomerPlan.TIER_SELF_HOSTED_BASIC}",
@@ -8894,9 +8904,10 @@ def test_redirect_for_remote_server_billing_page_downgrade_at_free_trial_end(
88948904
self.assert_in_response(substring, response)
88958905

88968906
# schedule downgrade
8897-
with time_machine.travel(self.now + timedelta(days=3), tick=False), self.assertLogs(
8898-
"corporate.stripe", "INFO"
8899-
) as m:
8907+
with (
8908+
time_machine.travel(self.now + timedelta(days=3), tick=False),
8909+
self.assertLogs("corporate.stripe", "INFO") as m,
8910+
):
89008911
response = self.client_billing_patch(
89018912
"/billing/plan",
89028913
{"status": CustomerPlan.DOWNGRADE_AT_END_OF_FREE_TRIAL},
@@ -9210,8 +9221,9 @@ def test_upgrade_server_to_fixed_price_plan_pay_by_invoice(self, *mocks: Mock) -
92109221
self.execute_remote_billing_authentication_flow(hamlet.delivery_email, hamlet.full_name)
92119222
mock_invoice = MagicMock()
92129223
mock_invoice.hosted_invoice_url = "payments_page_url"
9213-
with time_machine.travel(self.now, tick=False), mock.patch(
9214-
"stripe.Invoice.retrieve", return_value=mock_invoice
9224+
with (
9225+
time_machine.travel(self.now, tick=False),
9226+
mock.patch("stripe.Invoice.retrieve", return_value=mock_invoice),
92159227
):
92169228
result = self.client_get(
92179229
f"{self.billing_session.billing_base_url}/upgrade/?tier={CustomerPlan.TIER_SELF_HOSTED_BASIC}",
@@ -9663,9 +9675,11 @@ def test_legacy_plan_ends_on_plan_end_date(self, *mocks: Mock) -> None:
96639675
self.remote_server.plan_type, RemoteZulipServer.PLAN_TYPE_SELF_MANAGED_LEGACY
96649676
)
96659677

9666-
with mock.patch("stripe.Invoice.create") as invoice_create, mock.patch(
9667-
"corporate.lib.stripe.send_email"
9668-
) as send_email, time_machine.travel(plan_end_date, tick=False):
9678+
with (
9679+
mock.patch("stripe.Invoice.create") as invoice_create,
9680+
mock.patch("corporate.lib.stripe.send_email") as send_email,
9681+
time_machine.travel(plan_end_date, tick=False),
9682+
):
96699683
invoice_plans_as_needed()
96709684
# Verify that for legacy plan with no next plan scheduled,
96719685
# invoice overdue email is not sent even if the last audit log
@@ -9730,9 +9744,11 @@ def test_invoice_scheduled_upgrade_server_legacy_plan(self, *mocks: Mock) -> Non
97309744
)
97319745
licenses = max(min_licenses, server_user_count)
97329746

9733-
with mock.patch("stripe.Invoice.finalize_invoice") as invoice_create, mock.patch(
9734-
"corporate.lib.stripe.send_email"
9735-
) as send_email, time_machine.travel(end_date, tick=False):
9747+
with (
9748+
mock.patch("stripe.Invoice.finalize_invoice") as invoice_create,
9749+
mock.patch("corporate.lib.stripe.send_email") as send_email,
9750+
time_machine.travel(end_date, tick=False),
9751+
):
97369752
invoice_plans_as_needed()
97379753
# Verify that for legacy plan with next plan scheduled, invoice
97389754
# overdue email is sent if the last audit log is stale.

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.black]
22
line-length = 100
3-
target-version = ["py38"]
3+
target-version = ["py310"]
44

55
[tool.isort]
66
src_paths = [".", "tools"]
@@ -99,7 +99,7 @@ warn_required_dynamic_aliases = true
9999
[tool.ruff]
100100
line-length = 100
101101
src = [".", "tools"]
102-
target-version = "py38"
102+
target-version = "py310"
103103

104104
[tool.ruff.lint]
105105
# See https://github.com/astral-sh/ruff#rules for error code definitions.

scripts/lib/sharding.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ def write_updated_configs() -> None:
3333
expected_ports = list(range(9800, ports[-1] + 1))
3434
assert ports == expected_ports, f"ports ({ports}) must be contiguous, starting with 9800"
3535

36-
with open("/etc/zulip/nginx_sharding_map.conf.tmp", "w") as nginx_sharding_conf_f, open(
37-
"/etc/zulip/sharding.json.tmp", "w"
38-
) as sharding_json_f:
36+
with (
37+
open("/etc/zulip/nginx_sharding_map.conf.tmp", "w") as nginx_sharding_conf_f,
38+
open("/etc/zulip/sharding.json.tmp", "w") as sharding_json_f,
39+
):
3940
if len(ports) == 1:
4041
nginx_sharding_conf_f.write('map "" $tornado_server {\n')
4142
nginx_sharding_conf_f.write(" default http://tornado;\n")

scripts/lib/zulip_tools.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
import sys
1616
import time
1717
import uuid
18+
import zoneinfo
1819
from collections.abc import Sequence
1920
from datetime import datetime, timedelta
2021
from typing import IO, Any, Literal, overload
2122
from urllib.parse import SplitResult
2223

23-
import zoneinfo
24-
2524
DEPLOYMENTS_DIR = "/home/zulip/deployments"
2625
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")
2726
TIMESTAMP_FORMAT = "%Y-%m-%d-%H-%M-%S"

tools/setup/build_timezone_values

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import json
33
import os
44
import sys
5-
65
import zoneinfo
76

87
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../")

tools/test-help-documentation

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ def vnu_servlet() -> Iterator[None]:
5858
proc.terminate()
5959

6060

61-
with vnu_servlet(), test_server_running(
62-
options.skip_provision_check, external_host, log_file=LOG_FILE, dots=True
61+
with (
62+
vnu_servlet(),
63+
test_server_running(options.skip_provision_check, external_host, log_file=LOG_FILE, dots=True),
6364
):
6465
ret_help_doc = subprocess.call(
6566
["scrapy", "crawl_with_status", *extra_args, "help_documentation_crawler"],

tools/tests/test_zulint_custom_rules.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ def test_rule_patterns(self) -> None:
5858

5959
for line in rule.get("bad_lines", []):
6060
for filename in rule.get("include_only", {"foo.bar"}):
61-
with patch(
62-
"builtins.open", return_value=StringIO(line + "\n\n"), autospec=True
63-
), patch("builtins.print"):
61+
with (
62+
patch("builtins.open", return_value=StringIO(line + "\n\n"), autospec=True),
63+
patch("builtins.print"),
64+
):
6465
self.assertTrue(
6566
RuleList([], [rule]).custom_check_file(filename, "baz", ""),
6667
f"The pattern '{pattern}' didn't match the line '{line}' while it should.",

zerver/actions/realm_settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import logging
2+
import zoneinfo
23
from email.headerregistry import Address
34
from typing import Any, Literal
45

5-
import zoneinfo
66
from django.conf import settings
77
from django.db import transaction
88
from django.utils.timezone import get_current_timezone_name as timezone_get_current_timezone_name

zerver/lib/email_notifications.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import re
66
import subprocess
77
import sys
8+
import zoneinfo
89
from collections import defaultdict
910
from dataclasses import dataclass
1011
from datetime import timedelta
1112
from email.headerregistry import Address
1213
from typing import Any
1314

1415
import lxml.html
15-
import zoneinfo
1616
from bs4 import BeautifulSoup
1717
from django.conf import settings
1818
from django.contrib.auth import get_backends

zerver/lib/test_classes.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,10 @@ def run(self, result: TestResult | None = None) -> TestResult | None: # nocover
226226
if not settings.BAN_CONSOLE_OUTPUT and self.expected_console_output is None:
227227
return super().run(result)
228228
extra_output_finder = ExtraConsoleOutputFinder()
229-
with tee_stderr_and_find_extra_console_output(
230-
extra_output_finder
231-
), tee_stdout_and_find_extra_console_output(extra_output_finder):
229+
with (
230+
tee_stderr_and_find_extra_console_output(extra_output_finder),
231+
tee_stdout_and_find_extra_console_output(extra_output_finder),
232+
):
232233
test_result = super().run(result)
233234
if extra_output_finder.full_extra_output and (
234235
test_result is None or test_result.wasSuccessful()
@@ -1567,9 +1568,13 @@ def simulated_markdown_failure(self) -> Iterator[None]:
15671568
This raises a failure inside of the try/except block of
15681569
markdown.__init__.do_convert.
15691570
"""
1570-
with mock.patch(
1571-
"zerver.lib.markdown.unsafe_timeout", side_effect=subprocess.CalledProcessError(1, [])
1572-
), self.assertLogs(level="ERROR"): # For markdown_logger.exception
1571+
with (
1572+
mock.patch(
1573+
"zerver.lib.markdown.unsafe_timeout",
1574+
side_effect=subprocess.CalledProcessError(1, []),
1575+
),
1576+
self.assertLogs(level="ERROR"),
1577+
): # For markdown_logger.exception
15731578
yield
15741579

15751580
def create_default_device(

0 commit comments

Comments
 (0)