]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Move custom 2.0 deprecation warning message
authorStephen Rosen <sirosen@globus.org>
Thu, 15 Apr 2021 18:35:03 +0000 (18:35 +0000)
committerStephen Rosen <sirosen@globus.org>
Fri, 7 May 2021 15:59:59 +0000 (15:59 +0000)
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
lib/sqlalchemy/util/deprecations.py

index 55b1eb8a39784c822f78e80152fe39a7d9e5943e..27e02bb899a208846fd533bdd7c85c4b376585e9 100644 (file)
@@ -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."""
index 1369d61dce429b9a0121131bb5a5b49bef3513d4..3564d60a3377ac76b5af6f45c7855e752ed53895 100644 (file)
@@ -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