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.

ruff: Fix UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)`.

Anders Kaseorg1464009faed3
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index b1ddce93142..97be7170435 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -500,7 +500,7 @@ def catch_stripe_errors(func: Callable[ParamT, ReturnT]) -> Callable[ParamT, Ret
err.get("code"),
err.get("param"),
)
- if isinstance(e, (stripe.RateLimitError, stripe.APIConnectionError)): # nocoverage TODO
+ if isinstance(e, stripe.RateLimitError | stripe.APIConnectionError): # nocoverage TODO
raise StripeConnectionError(
"stripe connection error",
_("Something went wrong. Please wait a few seconds and try again."),
@@ -3252,7 +3252,7 @@ class BillingSession(ABC):
def get_sponsorship_request_context(self) -> dict[str, Any] | None:
customer = self.get_customer()
is_remotely_hosted = isinstance(
- self, (RemoteRealmBillingSession, RemoteServerBillingSession)
+ self, RemoteRealmBillingSession | RemoteServerBillingSession
)
plan_name = "Zulip Cloud Free"
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index 32d443f43ce..3e69ebabcea 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -6495,7 +6495,7 @@ class TestRemoteBillingWriteAuditLog(StripeTestCase):
audit_log_model = cast(
type[RemoteRealmAuditLog] | type[RemoteZulipServerAuditLog], audit_log_class
)
- assert isinstance(remote_user, (RemoteRealmBillingUser, RemoteServerBillingUser))
+ assert isinstance(remote_user, RemoteRealmBillingUser | RemoteServerBillingUser)
# No acting user:
session = session_class(remote_object)
session.write_to_audit_log(
diff --git a/zerver/lib/data_types.py b/zerver/lib/data_types.py
index ffdabe316b7..5f23670f5f8 100644
--- a/zerver/lib/data_types.py
+++ b/zerver/lib/data_types.py
@@ -113,7 +113,7 @@ class NumberType:
OpenAPI, because isinstance(4, float) == False"""
def check_data(self, var_name: str, val: Any | None) -> None:
- if isinstance(val, (int, float)):
+ if isinstance(val, int | float):
return
raise AssertionError(f"{var_name} is not a number")
@@ -185,7 +185,7 @@ class TupleType:
sub_types: Sequence[Any]
def check_data(self, var_name: str, val: Any) -> None:
- if not isinstance(val, (list, tuple)):
+ if not isinstance(val, list | tuple):
raise AssertionError(f"{var_name} is not a list/tuple")
if len(val) != len(self.sub_types):
diff --git a/zerver/lib/validator.py b/zerver/lib/validator.py
index 948218bce99..80345500b7a 100644
--- a/zerver/lib/validator.py
+++ b/zerver/lib/validator.py
@@ -624,7 +624,7 @@ def check_string_or_int_list(var_name: str, val: object) -> str | list[int]:
def check_string_or_int(var_name: str, val: object) -> str | int:
- if isinstance(val, (str, int)):
+ if isinstance(val, str | int):
return val
raise ValidationError(_("{var_name} is not a string or integer").format(var_name=var_name))
@@ -654,7 +654,7 @@ class WildValue:
return self.value == other
def __len__(self) -> int:
- if not isinstance(self.value, (dict, list, str)):
+ if not isinstance(self.value, dict | list | str):
raise ValidationError(
_("{var_name} does not have a length").format(var_name=self.var_name)
)
diff --git a/zerver/openapi/markdown_extension.py b/zerver/openapi/markdown_extension.py
index fcf8f140653..cb219d95216 100644
--- a/zerver/openapi/markdown_extension.py
+++ b/zerver/openapi/markdown_extension.py
@@ -254,7 +254,7 @@ cURL example."""
# Booleans are effectively JSON-encoded, in that we pass
# true/false, not the Python str(True) = "True"
- if parameter.json_encoded or isinstance(example_value, (bool, float, int)):
+ if parameter.json_encoded or isinstance(example_value, bool | float | int):
example_value = json.dumps(example_value)
else:
assert isinstance(example_value, str)
diff --git a/zerver/views/registration.py b/zerver/views/registration.py
index 70fc2826504..f478242566b 100644
--- a/zerver/views/registration.py
+++ b/zerver/views/registration.py
@@ -175,7 +175,7 @@ def check_prereg_key(
prereg_object = get_object_from_key(
confirmation_key, confirmation_types, mark_object_used=False
)
- assert isinstance(prereg_object, (PreregistrationRealm, PreregistrationUser))
+ assert isinstance(prereg_object, PreregistrationRealm | PreregistrationUser)
confirmation_obj = prereg_object.confirmation.get()
realm_creation = confirmation_obj.type == Confirmation.REALM_CREATION
diff --git a/zerver/views/sentry.py b/zerver/views/sentry.py
index f21fb4f219e..ead60b929e4 100644
--- a/zerver/views/sentry.py
+++ b/zerver/views/sentry.py
@@ -100,7 +100,7 @@ def sentry_tunnel(
# failing to connect at the TCP level will report as
# ProxyErrors.
def open_circuit_for(exc_type: type[Exception], exc_value: Exception) -> bool:
- if issubclass(exc_type, (ProxyError, Timeout)):
+ if issubclass(exc_type, ProxyError | Timeout):
return True
if isinstance(exc_value, HTTPError):
response = exc_value.response