Skip to content

Commit

Permalink
Use the new Python 3.8 walrus operator and simplify some if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshData committed Oct 18, 2023
1 parent 40a6e32 commit fcfa369
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
9 changes: 3 additions & 6 deletions email_validator/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def validate_email_local_part(local: str, allow_smtputf8: bool = True, allow_emp
# so if it was originally quoted (quoted_local_part is True) and this regex matches,
# it's ok.
# (RFC 5321 4.1.2 / RFC 5322 3.2.4).
m = DOT_ATOM_TEXT.match(local)
if m:
if DOT_ATOM_TEXT.match(local):
# It's valid. And since it's just the permitted ASCII characters,
# it's normalized and safe. If the local part was originally quoted,
# the quoting was unnecessary and it'll be returned as normalized to
Expand All @@ -89,8 +88,7 @@ def validate_email_local_part(local: str, allow_smtputf8: bool = True, allow_emp
# RFC 6531 section 3.3.
valid: Optional[str] = None
requires_smtputf8 = False
m = DOT_ATOM_TEXT_INTL.match(local)
if m:
if DOT_ATOM_TEXT_INTL.match(local):
# But international characters in the local part may not be permitted.
if not allow_smtputf8:
# Check for invalid characters against the non-internationalized
Expand Down Expand Up @@ -347,8 +345,7 @@ def validate_email_domain_name(domain, test_environment=False, globally_delivera

# Check the syntax of the string returned by idna.encode.
# It should never fail.
m = DOT_ATOM_TEXT_HOSTNAME.match(ascii_domain)
if not m:
if not DOT_ATOM_TEXT_HOSTNAME.match(ascii_domain):
raise EmailSyntaxError("The email address contains invalid characters after the @-sign after IDNA encoding.")

# Check the length of the domain name in bytes.
Expand Down
3 changes: 1 addition & 2 deletions email_validator/validate_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def validate_email(
# part if the local part is quoted. If the address is quoted,
# split it at a non-escaped @-sign and unescape the escaping.
quoted_local_part = False
m = QUOTED_LOCAL_PART_ADDR.match(email)
if m:
if m := QUOTED_LOCAL_PART_ADDR.match(email):
quoted_local_part = True
local_part, domain_part = m.groups()

Expand Down

0 comments on commit fcfa369

Please sign in to comment.