mirror of https://github.com/zulip/zulip.git
extract_recipients: Enforce str as incoming type.
After removing internal_send_message() in a recent commit, we now have only two callers for extract_recipients, and they are both related to our REQ mechanism that always passes strings to converters. (If there are default values, REQ does not call the converters.) We therefore make two changes: - use the more strict annotation of "str" for the `s` parameter - don't bother with the isinstance check
This commit is contained in:
parent
8c3eaeb872
commit
96132fe0e9
|
@ -2028,19 +2028,14 @@ def already_sent_mirrored_message_id(message: Message) -> Optional[int]:
|
||||||
return messages[0].id
|
return messages[0].id
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def extract_recipients(
|
def extract_recipients(s: str) -> Union[List[str], List[int]]:
|
||||||
s: Union[str, Iterable[str], Iterable[int]]
|
|
||||||
) -> Union[List[str], List[int]]:
|
|
||||||
# We try to accept multiple incoming formats for recipients.
|
# We try to accept multiple incoming formats for recipients.
|
||||||
# See test_extract_recipients() for examples of what we allow.
|
# See test_extract_recipients() for examples of what we allow.
|
||||||
|
|
||||||
if isinstance(s, str):
|
|
||||||
try:
|
try:
|
||||||
data = ujson.loads(s)
|
data = ujson.loads(s)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
data = s
|
data = s
|
||||||
else:
|
|
||||||
data = s
|
|
||||||
|
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
data = data.split(',')
|
data = data.split(',')
|
||||||
|
|
|
@ -652,7 +652,7 @@ class ExtractedRecipientsTest(TestCase):
|
||||||
extract_recipients(s)
|
extract_recipients(s)
|
||||||
|
|
||||||
# Empty list
|
# Empty list
|
||||||
self.assertEqual(extract_recipients([]), [])
|
self.assertEqual(extract_recipients('[]'), [])
|
||||||
|
|
||||||
# Heterogeneous lists are not supported
|
# Heterogeneous lists are not supported
|
||||||
mixed = ujson.dumps(['eeshan@example.com', 3, 4])
|
mixed = ujson.dumps(['eeshan@example.com', 3, 4])
|
||||||
|
|
Loading…
Reference in New Issue