Coverage for kwai/core/domain/value_objects/email_address.py: 91%
11 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
1"""Module for an email address value object."""
2from dataclasses import dataclass
4from pyisemail import is_email
7class InvalidEmailException(Exception):
8 """Raised when the email address is not valid."""
11@dataclass(frozen=True, slots=True)
12class EmailAddress:
13 """A value object for an email address."""
15 email: str
17 def __post_init__(self):
18 """Check if the email address is valid."""
19 if not is_email(self.email):
20 raise InvalidEmailException()
22 def __str__(self):
23 """Return the string representation of an email address."""
24 return self.email