From 68b9d1892dc6007844a80acf5677cf6166bf5533 Mon Sep 17 00:00:00 2001 From: commonism Date: Mon, 5 Jun 2023 16:38:36 +0200 Subject: [PATCH] Exposing a version str & deprecating the email attribute (#110) * expose version as __version__ * assist ValidatedEmail.email deprecation --- email_validator/__init__.py | 4 ++-- email_validator/exceptions_types.py | 7 +++++++ email_validator/version.py | 1 + setup.cfg | 2 +- tests/test_main.py | 7 +++++++ 5 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 email_validator/version.py diff --git a/email_validator/__init__.py b/email_validator/__init__.py index d5f26a2..c3b5929 100644 --- a/email_validator/__init__.py +++ b/email_validator/__init__.py @@ -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): diff --git a/email_validator/exceptions_types.py b/email_validator/exceptions_types.py index 9a1b331..ee9d50a 100644 --- a/email_validator/exceptions_types.py +++ b/email_validator/exceptions_types.py @@ -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): diff --git a/email_validator/version.py b/email_validator/version.py new file mode 100644 index 0000000..7857319 --- /dev/null +++ b/email_validator/version.py @@ -0,0 +1 @@ +__version__ = "2.0.0.post2" \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index d299498..dc97892 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/tests/test_main.py b/tests/test_main.py index e32af94..dc01bc1 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -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"testaddr@example.tld" + valid_email = validate_email(input_email, check_deliverability=False) + with pytest.raises(DeprecationWarning): + assert valid_email.email is not None \ No newline at end of file