Skip to content

Commit 68b9d18

Browse files
authored
Exposing a version str & deprecating the email attribute (#110)
* expose version as __version__ * assist ValidatedEmail.email deprecation
1 parent 1b3e4c6 commit 68b9d18

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

email_validator/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
from .exceptions_types import ValidatedEmail, EmailNotValidError, \
55
EmailSyntaxError, EmailUndeliverableError
66
from .validate_email import validate_email
7-
7+
from .version import __version__
88

99
__all__ = ["validate_email",
1010
"ValidatedEmail", "EmailNotValidError",
1111
"EmailSyntaxError", "EmailUndeliverableError",
12-
"caching_resolver"]
12+
"caching_resolver", "__version__"]
1313

1414

1515
def caching_resolver(*args, **kwargs):

email_validator/exceptions_types.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ def __getattr__(self, key):
7878
return self.normalized
7979
raise AttributeError()
8080

81+
@property
82+
def email(self):
83+
import warnings
84+
warnings.warn("ValidatedEmail.email is deprecated and will be removed, use ValidatedEmail.normalized instead", DeprecationWarning)
85+
return self.normalized
86+
87+
8188
"""For backwards compatibility, some fields are also exposed through a dict-like interface. Note
8289
that some of the names changed when they became attributes."""
8390
def __getitem__(self, key):

email_validator/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "2.0.0.post2"

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = email_validator
3-
version = 2.0.0.post2
3+
version = attr: email_validator.version.__version__
44
description = A robust email address syntax and deliverability validation library.
55
long_description = file: README.md
66
long_description_content_type = text/markdown

tests/test_main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,10 @@ def test_bytes_input():
5858
input_email = "testaddr中example.tld".encode("utf32")
5959
with pytest.raises(EmailSyntaxError):
6060
validate_email(input_email, check_deliverability=False)
61+
62+
63+
def test_deprecation():
64+
input_email = b"[email protected]"
65+
valid_email = validate_email(input_email, check_deliverability=False)
66+
with pytest.raises(DeprecationWarning):
67+
assert valid_email.email is not None

0 commit comments

Comments
 (0)