From 55142564bbbea52d9e614e44251212dd10eceab5 Mon Sep 17 00:00:00 2001 From: David Lord Date: Thu, 23 May 2024 09:06:51 -0700 Subject: [PATCH] deprecate `__version__` --- CHANGES.md | 2 ++ src/flask_mail/__init__.py | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 2e0c3fb..5ce4f03 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,8 @@ Unreleased - Use `pyproject.toml` for packaging metadata. - Use `flit_core` as build backend. - Apply code formatting and linting tools. +- Deprecate the `__version__` attribute. Use feature detection or + `importlib.metadata.version("flask-mail")` instead. ## Version 0.9.1 diff --git a/src/flask_mail/__init__.py b/src/flask_mail/__init__.py index 351e681..2fd0ffa 100644 --- a/src/flask_mail/__init__.py +++ b/src/flask_mail/__init__.py @@ -1,9 +1,8 @@ -__version__ = "0.10.0.dev" - import re import smtplib import time import unicodedata +import warnings from contextlib import contextmanager from email import charset from email import policy @@ -591,3 +590,19 @@ def __getattr__(self, name): in testing mode, even though the email will not actually be sent. """, ) + + +def __getattr__(name): + if name == "__version__": + import importlib.metadata + + warnings.warn( + "The '__version__' attribute is deprecated and will be removed in" + " Flask-Mail 1.0. Use feature detection or" + " 'importlib.metadata.version(\"flask-mail\")' instead.", + DeprecationWarning, + stacklevel=2, + ) + return importlib.metadata.version("flask-mail") + + raise AttributeError(name)