mirror of
https://github.com/zulip/zulip.git
synced 2025-11-17 04:12:02 +00:00
python: Use isinstance with a tuple for testing multiple types.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
@@ -179,8 +179,7 @@ def catch_stripe_errors(func: CallableT) -> CallableT:
|
||||
if isinstance(e, stripe.error.CardError):
|
||||
# TODO: Look into i18n for this
|
||||
raise StripeCardError('card error', err.get('message'))
|
||||
if isinstance(e, stripe.error.RateLimitError) or \
|
||||
isinstance(e, stripe.error.APIConnectionError): # nocoverage TODO
|
||||
if isinstance(e, (stripe.error.RateLimitError, stripe.error.APIConnectionError)): # nocoverage TODO
|
||||
raise StripeConnectionError(
|
||||
'stripe connection error',
|
||||
_("Something went wrong. Please wait a few seconds and try again."))
|
||||
|
||||
@@ -102,7 +102,7 @@ def enforce_timely_test_completion(test_method: Callable[..., ReturnT], test_nam
|
||||
else:
|
||||
max_delay = 0.4 # seconds
|
||||
|
||||
assert isinstance(result, TextTestResult) or isinstance(result, RemoteTestResult)
|
||||
assert isinstance(result, (TextTestResult, RemoteTestResult))
|
||||
|
||||
if delay > max_delay:
|
||||
msg = f'** Test is TOO slow: {test_name} ({delay:.3f} s)\n'
|
||||
|
||||
@@ -43,7 +43,7 @@ def get_sequence_type_str(x: Sequence[Any]) -> str:
|
||||
else:
|
||||
return f'{container_type}([{elem_type}, ...])'
|
||||
|
||||
expansion_blacklist = [str, bytes]
|
||||
expansion_blacklist = (str, bytes)
|
||||
|
||||
def get_type_str(x: Any) -> str:
|
||||
if x is None:
|
||||
@@ -58,7 +58,7 @@ def get_type_str(x: Any) -> str:
|
||||
return '(' + ', '.join(types) + ')'
|
||||
elif isinstance(x, Mapping):
|
||||
return get_mapping_type_str(x)
|
||||
elif isinstance(x, Sequence) and not any(isinstance(x, t) for t in expansion_blacklist):
|
||||
elif isinstance(x, Sequence) and not isinstance(x, expansion_blacklist):
|
||||
return get_sequence_type_str(x)
|
||||
else:
|
||||
return type(x).__name__
|
||||
|
||||
@@ -397,7 +397,7 @@ def check_string_or_int_list(var_name: str, val: object) -> Union[str, List[int]
|
||||
return check_list(check_int)(var_name, val)
|
||||
|
||||
def check_string_or_int(var_name: str, val: object) -> Union[str, int]:
|
||||
if isinstance(val, str) or isinstance(val, int):
|
||||
if isinstance(val, (str, int)):
|
||||
return val
|
||||
|
||||
raise ValidationError(_('{var_name} is not a string or integer').format(var_name=var_name))
|
||||
|
||||
Reference in New Issue
Block a user