Skip to content

Commit e943a0f

Browse files
committed
Raise TypeError when an invalid argument is passed for email, closes #155
1 parent f90d256 commit e943a0f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

email_validator/validate_email.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,18 @@ def validate_email(
5959
if timeout is None and dns_resolver is None:
6060
timeout = DEFAULT_TIMEOUT
6161

62-
# Allow email to be a str or bytes instance. If bytes,
63-
# it must be ASCII because that's how the bytes work
64-
# on the wire with SMTP.
65-
if not isinstance(email, str):
62+
if isinstance(email, str):
63+
pass
64+
elif isinstance(email, bytes):
65+
# Allow email to be a bytes instance as if it is what
66+
# will be transmitted on the wire. But assume SMTPUTF8
67+
# is unavailable, so it must be ASCII.
6668
try:
6769
email = email.decode("ascii")
6870
except ValueError as e:
6971
raise EmailSyntaxError("The email address is not valid ASCII.") from e
72+
else:
73+
raise TypeError("email must be str or bytes")
7074

7175
# Split the address into the display name (or None), the local part
7276
# (before the @-sign), and the domain part (after the @-sign).

0 commit comments

Comments
 (0)