From 1464009faed37ea413b869b3edc4fd6e5257788a Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 11 Jul 2024 17:30:27 -0700 Subject: [PATCH] ruff: Fix UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)`. Signed-off-by: Anders Kaseorg --- corporate/lib/stripe.py | 4 ++-- corporate/tests/test_stripe.py | 2 +- zerver/lib/data_types.py | 4 ++-- zerver/lib/validator.py | 4 ++-- zerver/openapi/markdown_extension.py | 2 +- zerver/views/registration.py | 2 +- zerver/views/sentry.py | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index b1ddce9314..97be717043 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 32d443f43c..3e69ebabce 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 ffdabe316b..5f23670f5f 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 948218bce9..80345500b7 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 fcf8f14065..cb219d9521 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 70fc282650..f478242566 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 f21fb4f219..ead60b929e 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