From d57446619f3b331c88208d2d80ebbe656ff119f5 Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Thu, 15 Apr 2021 18:35:03 +0000 Subject: [PATCH] Move custom 2.0 deprecation warning message Rather than appending to the message via the deprecation utilities, the RemovedIn20Warning class has a custom __str__ which appends the desired info to its message. --- lib/sqlalchemy/exc.py | 6 ++++++ lib/sqlalchemy/util/deprecations.py | 7 +------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py index 55b1eb8a39..27e02bb899 100644 --- a/lib/sqlalchemy/exc.py +++ b/lib/sqlalchemy/exc.py @@ -681,6 +681,12 @@ class RemovedIn20Warning(SADeprecationWarning): deprecated_since = "1.4" "Indicates the version that started raising this deprecation warning" + def __str__(self): + return ( + super(RemovedIn20Warning, self).__str__() + + " (Background on SQLAlchemy 2.0 at: http://sqlalche.me/e/b8d9)" + ) + class MovedIn20Warning(RemovedIn20Warning): """Subtype of RemovedIn20Warning to indicate an API that moved only.""" diff --git a/lib/sqlalchemy/util/deprecations.py b/lib/sqlalchemy/util/deprecations.py index 1369d61dce..3564d60a33 100644 --- a/lib/sqlalchemy/util/deprecations.py +++ b/lib/sqlalchemy/util/deprecations.py @@ -27,14 +27,9 @@ if os.getenv("SQLALCHEMY_WARN_20", "false").lower() in ("true", "yes", "1"): def _warn_with_version(msg, version, type_, stacklevel, code=None): - is_20 = issubclass(type_, exc.RemovedIn20Warning) - - if is_20 and not SQLALCHEMY_WARN_20: + if issubclass(type_, exc.RemovedIn20Warning) and not SQLALCHEMY_WARN_20: return - if is_20: - msg += " (Background on SQLAlchemy 2.0 at: http://sqlalche.me/e/b8d9)" - warn = type_(msg, code=code) warn.deprecated_since = version -- 2.47.2