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

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-07-11 17:30:27 -07:00 committed by Tim Abbott
parent 0fa5e7f629
commit 1464009fae
7 changed files with 10 additions and 10 deletions

View File

@ -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"

View File

@ -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(

View File

@ -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):

View File

@ -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)
)

View File

@ -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)

View File

@ -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

View File

@ -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