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:
Steve Howell 2020-02-11 16:13:27 +00:00 committed by Tim Abbott
parent 8c3eaeb872
commit 96132fe0e9
2 changed files with 5 additions and 10 deletions

View File

@ -2028,18 +2028,13 @@ 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
else:
data = s data = s
if isinstance(data, str): if isinstance(data, str):

View File

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