Skip to content

Commit 814b488

Browse files
committed
Use the new Python 3.8 walrus operator and simplify some if statements
1 parent 371c120 commit 814b488

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

email_validator/syntax.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ def validate_email_local_part(local: str, allow_smtputf8: bool = True, allow_emp
6969
# so if it was originally quoted (quoted_local_part is True) and this regex matches,
7070
# it's ok.
7171
# (RFC 5321 4.1.2 / RFC 5322 3.2.4).
72-
m = DOT_ATOM_TEXT.match(local)
73-
if m:
72+
if DOT_ATOM_TEXT.match(local):
7473
# It's valid. And since it's just the permitted ASCII characters,
7574
# it's normalized and safe. If the local part was originally quoted,
7675
# the quoting was unnecessary and it'll be returned as normalized to
@@ -89,8 +88,7 @@ def validate_email_local_part(local: str, allow_smtputf8: bool = True, allow_emp
8988
# RFC 6531 section 3.3.
9089
valid: Optional[str] = None
9190
requires_smtputf8 = False
92-
m = DOT_ATOM_TEXT_INTL.match(local)
93-
if m:
91+
if DOT_ATOM_TEXT_INTL.match(local):
9492
# But international characters in the local part may not be permitted.
9593
if not allow_smtputf8:
9694
# Check for invalid characters against the non-internationalized
@@ -347,8 +345,7 @@ def validate_email_domain_name(domain, test_environment=False, globally_delivera
347345

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

354351
# Check the length of the domain name in bytes.

email_validator/validate_email.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def validate_email(
5858
# part if the local part is quoted. If the address is quoted,
5959
# split it at a non-escaped @-sign and unescape the escaping.
6060
quoted_local_part = False
61-
m = QUOTED_LOCAL_PART_ADDR.match(email)
62-
if m:
61+
if m := QUOTED_LOCAL_PART_ADDR.match(email):
6362
quoted_local_part = True
6463
local_part, domain_part = m.groups()
6564

0 commit comments

Comments
 (0)