Skip to content

Commit

Permalink
Exposing a version str & deprecating the email attribute (#110)
Browse files Browse the repository at this point in the history
* expose version as __version__

* assist ValidatedEmail.email deprecation
  • Loading branch information
commonism authored Jun 5, 2023
1 parent 1b3e4c6 commit 68b9d18
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions email_validator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from .exceptions_types import ValidatedEmail, EmailNotValidError, \
EmailSyntaxError, EmailUndeliverableError
from .validate_email import validate_email

from .version import __version__

__all__ = ["validate_email",
"ValidatedEmail", "EmailNotValidError",
"EmailSyntaxError", "EmailUndeliverableError",
"caching_resolver"]
"caching_resolver", "__version__"]


def caching_resolver(*args, **kwargs):
Expand Down
7 changes: 7 additions & 0 deletions email_validator/exceptions_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ def __getattr__(self, key):
return self.normalized
raise AttributeError()

@property
def email(self):
import warnings
warnings.warn("ValidatedEmail.email is deprecated and will be removed, use ValidatedEmail.normalized instead", DeprecationWarning)
return self.normalized


"""For backwards compatibility, some fields are also exposed through a dict-like interface. Note
that some of the names changed when they became attributes."""
def __getitem__(self, key):
Expand Down
1 change: 1 addition & 0 deletions email_validator/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "2.0.0.post2"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = email_validator
version = 2.0.0.post2
version = attr: email_validator.version.__version__
description = A robust email address syntax and deliverability validation library.
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
7 changes: 7 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ def test_bytes_input():
input_email = "testaddr中example.tld".encode("utf32")
with pytest.raises(EmailSyntaxError):
validate_email(input_email, check_deliverability=False)


def test_deprecation():
input_email = b"[email protected]"
valid_email = validate_email(input_email, check_deliverability=False)
with pytest.raises(DeprecationWarning):
assert valid_email.email is not None

0 comments on commit 68b9d18

Please sign in to comment.