ashb commented on a change in pull request #6315: [AIRFLOW-5640] fix 
get_email_address_list types
URL: https://github.com/apache/airflow/pull/6315#discussion_r334658113
 
 

 ##########
 File path: airflow/utils/email.py
 ##########
 @@ -120,13 +122,22 @@ def send_MIME_email(e_from, e_to, mime_msg, 
dryrun=False):
         s.quit()
 
 
-def get_email_address_list(address_string):
-    if isinstance(address_string, str):
-        if ',' in address_string:
-            address_string = [address.strip() for address in 
address_string.split(',')]
-        elif ';' in address_string:
-            address_string = [address.strip() for address in 
address_string.split(';')]
-        else:
-            address_string = [address_string]
+def get_email_address_list(addresses: Union[str, Iterable[str]]) -> List[str]:
+    if isinstance(addresses, str):
+        return _get_email_list_from_str(addresses)
 
-    return address_string
+    elif isinstance(addresses, Iterable):
+        if not all(isinstance(item, str) for item in addresses):
+            raise TypeError("The items in your iterable must be strings.")
+        return list(addresses)
+
+    received_type = type(addresses).__name__
+    raise TypeError("Unexpected argument type: Received 
'{}'.".format(received_type))
+
+
+def _get_email_list_from_str(addresses: str) -> List[str]:
+    delimiters = [",", ";"]
+    for delimiter in delimiters:
+        if delimiter in addresses:
+            return [address.strip() for address in addresses.split(delimiter)]
+    return [addresses]
 
 Review comment:
   Could you add one further test case that covers this (A single email in a 
string) as I don't think it's yet covered?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to