python: Reformat with Black 22 (stable).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-02-15 14:45:41 -08:00
parent e53f9fad29
commit 1629d6bfb3
20 changed files with 60 additions and 36 deletions

View File

@ -59,7 +59,7 @@ def generate_time_series_data(
)
growth_base = growth ** (1.0 / (length - 1))
values_no_noise = [
seasonality[i % len(seasonality)] * (growth_base ** i) for i in range(length)
seasonality[i % len(seasonality)] * (growth_base**i) for i in range(length)
]
seed(random_seed)

View File

@ -3860,7 +3860,7 @@ class StripeWebhookEndpointTest(ZulipTestCase):
"data": {"object": {"object": "checkout.session", "id": "stripe_session_id"}},
}
expected_error_message = fr"Mismatch between billing system Stripe API version({STRIPE_API_VERSION}) and Stripe webhook event API version(1991-02-20)."
expected_error_message = rf"Mismatch between billing system Stripe API version({STRIPE_API_VERSION}) and Stripe webhook event API version(1991-02-20)."
with self.assertLogs("corporate.stripe", "ERROR") as error_log:
self.client_post(
"/stripe/webhook/",

View File

@ -104,9 +104,9 @@ if is_in_recovery[0][0] == "t":
report("CRITICAL", f"replica is in state {state}, not streaming")
msg = f"replica is {replay_lag} bytes behind in replay of WAL logs from {primary_server}"
if replay_lag > 5 * 16 * 1024 ** 2:
if replay_lag > 5 * 16 * 1024**2:
report("CRITICAL", msg)
elif replay_lag > 16 * 1024 ** 2:
elif replay_lag > 16 * 1024**2:
report("WARNING", msg)
else:
report("OK", msg)
@ -135,9 +135,9 @@ else:
for lag_type in ("write", "flush", "replay"):
lag_bytes = lag[lag_type]
msg = f"replica {client_addr} is {lag_bytes} bytes behind in {lag_type} of WAL logs"
if lag_bytes > 5 * 16 * 1024 ** 2:
if lag_bytes > 5 * 16 * 1024**2:
report("CRITICAL", msg)
elif lag_bytes > 16 * 1024 ** 2:
elif lag_bytes > 16 * 1024**2:
report("WARNING", msg)
else:
report("OK", msg)

View File

@ -91,9 +91,30 @@ beautifulsoup4==4.10.0 \
# -r requirements/common.in
# pyoembed
# zulip-bots
black==21.12b0 \
--hash=sha256:77b80f693a569e2e527958459634f18df9b0ba2625ba4e0c2d5da5be42e6f2b3 \
--hash=sha256:a615e69ae185e08fdd73e4715e260e2479c861b5740057fde6e8b4e3b7dd589f
black==22.1.0 \
--hash=sha256:07e5c049442d7ca1a2fc273c79d1aecbbf1bc858f62e8184abe1ad175c4f7cc2 \
--hash=sha256:0e21e1f1efa65a50e3960edd068b6ae6d64ad6235bd8bfea116a03b21836af71 \
--hash=sha256:1297c63b9e1b96a3d0da2d85d11cd9bf8664251fd69ddac068b98dc4f34f73b6 \
--hash=sha256:228b5ae2c8e3d6227e4bde5920d2fc66cc3400fde7bcc74f480cb07ef0b570d5 \
--hash=sha256:2d6f331c02f0f40aa51a22e479c8209d37fcd520c77721c034517d44eecf5912 \
--hash=sha256:2ff96450d3ad9ea499fc4c60e425a1439c2120cbbc1ab959ff20f7c76ec7e866 \
--hash=sha256:3524739d76b6b3ed1132422bf9d82123cd1705086723bc3e235ca39fd21c667d \
--hash=sha256:35944b7100af4a985abfcaa860b06af15590deb1f392f06c8683b4381e8eeaf0 \
--hash=sha256:373922fc66676133ddc3e754e4509196a8c392fec3f5ca4486673e685a421321 \
--hash=sha256:5fa1db02410b1924b6749c245ab38d30621564e658297484952f3d8a39fce7e8 \
--hash=sha256:6f2f01381f91c1efb1451998bd65a129b3ed6f64f79663a55fe0e9b74a5f81fd \
--hash=sha256:742ce9af3086e5bd07e58c8feb09dbb2b047b7f566eb5f5bc63fd455814979f3 \
--hash=sha256:7835fee5238fc0a0baf6c9268fb816b5f5cd9b8793423a75e8cd663c48d073ba \
--hash=sha256:8871fcb4b447206904932b54b567923e5be802b9b19b744fdff092bd2f3118d0 \
--hash=sha256:a7c0192d35635f6fc1174be575cb7915e92e5dd629ee79fdaf0dcfa41a80afb5 \
--hash=sha256:b1a5ed73ab4c482208d20434f700d514f66ffe2840f63a6252ecc43a9bc77e8a \
--hash=sha256:c8226f50b8c34a14608b848dc23a46e5d08397d009446353dad45e04af0c8e28 \
--hash=sha256:ccad888050f5393f0d6029deea2a33e5ae371fd182a697313bdbd835d3edaf9c \
--hash=sha256:dae63f2dbf82882fa3b2a3c49c32bffe144970a573cd68d247af6560fc493ae1 \
--hash=sha256:e2f69158a7d120fd641d1fa9a921d898e20d52e44a74a6fbbcc570a62a6bc8ab \
--hash=sha256:efbadd9b52c060a8fc3b9658744091cb33c31f830b3f074422ed27bad2b18e8f \
--hash=sha256:f5660feab44c2e3cb24b2419b998846cbb01c23c7fe645fee45087efa3da2d61 \
--hash=sha256:fdb8754b453fb15fad3f72cd9cad3e16776f0964d67cf30ebcbf10327a3777a3
# via -r requirements/dev.in
boto3==1.20.41 \
--hash=sha256:aaddf6cf93568b734ad62fd96991775bccc7f016e93ff4e98dc1aa4f7586440c \

View File

@ -259,7 +259,7 @@ elif args.from_git:
# Because `upgrade-zulip-from-git` needs to build static assets, it
# is at risk of being OOM killed on systems with limited free RAM.
mem_bytes = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES")
mem_gib = mem_bytes / (1024.0 ** 3) # e.g. 3.74
mem_gib = mem_bytes / (1024.0**3) # e.g. 3.74
# Ideally, we'd have 2 thresholds here, depending on whether the
# system is running queue workers multithreaded or multiprocess.

View File

@ -185,7 +185,7 @@ COMPILED_IGNORED_PHRASES = [
]
SPLIT_BOUNDARY = "?.!" # Used to split string into sentences.
SPLIT_BOUNDARY_REGEX = re.compile(fr"[{SPLIT_BOUNDARY}]")
SPLIT_BOUNDARY_REGEX = re.compile(rf"[{SPLIT_BOUNDARY}]")
# Regexes which check capitalization in sentences.
DISALLOWED = [

View File

@ -48,4 +48,4 @@ API_FEATURE_LEVEL = 115
# historical commits sharing the same major version, in which case a
# minor version bump suffices.
PROVISION_VERSION = "175.0"
PROVISION_VERSION = "176.0"

View File

@ -242,7 +242,7 @@ def get_web_link_regex() -> Pattern[str]:
nested_paren_chunk = nested_paren_chunk % (inner_paren_contents,)
file_links = r"| (?:file://(/[^/ ]*)+/?)" if settings.ENABLE_FILE_LINKS else r""
REGEX = fr"""
REGEX = rf"""
(?<![^\s'"\(,:<]) # Start after whitespace or specified chars
# (Double-negative lookbehind to allow start-of-string)
(?P<url> # Main group
@ -1785,7 +1785,7 @@ def prepare_linkifier_pattern(source: str) -> str:
whitespace, or opening delimiters, won't match if there are word
characters directly after, and saves what was matched as
OUTER_CAPTURE_GROUP."""
return fr"""(?P<{BEFORE_CAPTURE_GROUP}>^|\s|['"\(,:<])(?P<{OUTER_CAPTURE_GROUP}>{source})(?P<{AFTER_CAPTURE_GROUP}>$|[^\pL\pN])"""
return rf"""(?P<{BEFORE_CAPTURE_GROUP}>^|\s|['"\(,:<])(?P<{OUTER_CAPTURE_GROUP}>{source})(?P<{AFTER_CAPTURE_GROUP}>$|[^\pL\pN])"""
# Given a regular expression pattern, linkifies groups that match it

View File

@ -28,7 +28,7 @@ def get_subdomain(request: HttpRequest) -> str:
def get_subdomain_from_hostname(host: str) -> str:
m = re.search(fr"\.{settings.EXTERNAL_HOST}(:\d+)?$", host)
m = re.search(rf"\.{settings.EXTERNAL_HOST}(:\d+)?$", host)
if m:
subdomain = host[: m.start()]
if subdomain in settings.ROOT_SUBDOMAIN_ALIASES:
@ -36,7 +36,7 @@ def get_subdomain_from_hostname(host: str) -> str:
return subdomain
for subdomain, realm_host in settings.REALM_HOSTS.items():
if re.search(fr"^{realm_host}(:\d+)?$", host):
if re.search(rf"^{realm_host}(:\d+)?$", host):
return subdomain
return Realm.SUBDOMAIN_FOR_ROOT_DOMAIN

View File

@ -530,7 +530,7 @@ def validate_todo_data(todo_data: object) -> None:
# Converter functions for use with has_request_variables
def to_non_negative_int(s: str, max_int_size: int = 2 ** 32 - 1) -> int:
def to_non_negative_int(s: str, max_int_size: int = 2**32 - 1) -> int:
x = int(s)
if x < 0:
raise ValueError("argument is negative")

View File

@ -247,7 +247,7 @@ class Realm(models.Model):
disallow_disposable_email_addresses: bool = models.BooleanField(default=True)
authentication_methods: BitHandler = BitField(
flags=AUTHENTICATION_FLAGS,
default=2 ** 31 - 1,
default=2**31 - 1,
)
# Allow users to access web-public streams without login. This

View File

@ -169,7 +169,7 @@ def render_python_code_example(
def render_javascript_code_example(
function: str, admin_config: bool = False, **kwargs: Any
) -> List[str]:
pattern = fr'^add_example\(\s*"[^"]*",\s*{re.escape(json.dumps(function))},\s*\d+,\s*async \(client, console\) => \{{\n(.*?)^(?:\}}| *\}},\n)\);$'
pattern = rf'^add_example\(\s*"[^"]*",\s*{re.escape(json.dumps(function))},\s*\d+,\s*async \(client, console\) => \{{\n(.*?)^(?:\}}| *\}},\n)\);$'
with open("zerver/openapi/javascript_examples.js") as f:
m = re.search(pattern, f.read(), re.M | re.S)
if m is None:

View File

@ -5,7 +5,8 @@ from zerver.lib.test_classes import ZulipTestCase
class VersionTest(ZulipTestCase):
data = [
data = (
[
case.split()
for case in """
1.2.3 < 1.2.4
@ -27,10 +28,12 @@ class VersionTest(ZulipTestCase):
""".strip().split(
"\n"
)
] + [
]
+ [
["", "?", "1"],
["", "?", "a"],
]
)
def test_version_lt(self) -> None:
for ver1, cmp, ver2 in self.data:

View File

@ -771,7 +771,7 @@ class ValidatorTestCase(ZulipTestCase):
with self.assertRaisesRegex(ValueError, re.escape("5 is too large (max 4)")):
to_non_negative_int("5", max_int_size=4)
with self.assertRaisesRegex(ValueError, re.escape(f"{2**32} is too large (max {2**32-1})")):
to_non_negative_int(str(2 ** 32))
to_non_negative_int(str(2**32))
def test_check_float(self) -> None:
x: Any = 5.5

View File

@ -150,7 +150,7 @@ class EmailChangeTestCase(ZulipTestCase):
self.assertEqual(self.email_envelope_from(email_message), settings.NOREPLY_EMAIL_ADDRESS)
self.assertRegex(
self.email_display_from(email_message),
fr"^Zulip Account Security <{self.TOKENIZED_NOREPLY_REGEX}>\Z",
rf"^Zulip Account Security <{self.TOKENIZED_NOREPLY_REGEX}>\Z",
)
self.assertEqual(email_message.extra_headers["List-Id"], "Zulip Dev <zulip.testserver>")

View File

@ -381,7 +381,7 @@ class TestPasswordRestEmail(ZulipTestCase):
self.assertEqual(self.email_envelope_from(outbox[0]), settings.NOREPLY_EMAIL_ADDRESS)
self.assertRegex(
self.email_display_from(outbox[0]),
fr"^Zulip Account Security <{self.TOKENIZED_NOREPLY_REGEX}>\Z",
rf"^Zulip Account Security <{self.TOKENIZED_NOREPLY_REGEX}>\Z",
)
self.assertIn("reset your password", outbox[0].body)

View File

@ -380,7 +380,7 @@ class RealmTest(ZulipTestCase):
self.assertEqual(self.email_envelope_from(outbox[0]), settings.NOREPLY_EMAIL_ADDRESS)
self.assertRegex(
self.email_display_from(outbox[0]),
fr"^Zulip Account Security <{self.TOKENIZED_NOREPLY_REGEX}>\Z",
rf"^Zulip Account Security <{self.TOKENIZED_NOREPLY_REGEX}>\Z",
)
self.assertIn("Reactivate your Zulip organization", outbox[0].subject)
self.assertIn("Dear former administrators", outbox[0].body)

View File

@ -360,7 +360,7 @@ class PasswordResetTest(ZulipTestCase):
self.assertEqual(self.email_envelope_from(message), settings.NOREPLY_EMAIL_ADDRESS)
self.assertRegex(
self.email_display_from(message),
fr"^Zulip Account Security <{self.TOKENIZED_NOREPLY_REGEX}>\Z",
rf"^Zulip Account Security <{self.TOKENIZED_NOREPLY_REGEX}>\Z",
)
self.assertIn(f"{subdomain}.testserver", message.extra_headers["List-Id"])
@ -1036,7 +1036,7 @@ class InviteUserBase(ZulipTestCase):
self.assertEqual(self.email_envelope_from(outbox[0]), settings.NOREPLY_EMAIL_ADDRESS)
self.assertRegex(
self.email_display_from(outbox[0]), fr" <{self.TOKENIZED_NOREPLY_REGEX}>\Z"
self.email_display_from(outbox[0]), rf" <{self.TOKENIZED_NOREPLY_REGEX}>\Z"
)
self.assertEqual(outbox[0].extra_headers["List-Id"], "Zulip Dev <zulip.testserver>")

View File

@ -291,7 +291,7 @@ class NarrowBuilder:
base_stream_name = m.group(1)
matching_streams = get_active_streams(self.realm).filter(
name__iregex=fr"^(un)*{self._pg_re_escape(base_stream_name)}(\.d)*$"
name__iregex=rf"^(un)*{self._pg_re_escape(base_stream_name)}(\.d)*$"
)
recipient_ids = [matching_stream.recipient_id for matching_stream in matching_streams]
cond = column("recipient_id", Integer).in_(recipient_ids)

View File

@ -895,7 +895,7 @@ class Command(BaseCommand):
count = options["num_messages"] // threads
if i < options["num_messages"] % threads:
count += 1
jobs.append((count, personals_pairs, options, random.randint(0, 10 ** 10)))
jobs.append((count, personals_pairs, options, random.randint(0, 10**10)))
for job in jobs:
generate_and_send_messages(job)