]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Ignore all dunders when checking attributes in `sqlalchemy.util.langhelpers.TypingOnly`
authorEdgar Ramírez-Mondragón <edgarrm358@gmail.com>
Tue, 30 Apr 2024 01:53:07 +0000 (21:53 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 30 Apr 2024 16:13:15 +0000 (12:13 -0400)
Fixed an internal class that was testing for unexpected attributes to work
correctly under upcoming Python 3.13.   Pull request courtesy Edgar
Ramírez-Mondragón.

Fixes: #11334
Closes: #11335
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11335
Pull-request-sha: babd703e6e34b93722a54c3adf13aa792d3a03b3

Change-Id: Ia2e7392c9403e25266c7d30b987b577f49d008c0
(cherry picked from commit eb118e23a29a29469edb4c1927250f4b726de68e)

doc/build/changelog/unreleased_20/11334.rst [new file with mode: 0644]
lib/sqlalchemy/util/langhelpers.py

diff --git a/doc/build/changelog/unreleased_20/11334.rst b/doc/build/changelog/unreleased_20/11334.rst
new file mode 100644 (file)
index 0000000..48f590c
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, installation
+    :tickets: 11334
+
+    Fixed an internal class that was testing for unexpected attributes to work
+    correctly under upcoming Python 3.13.   Pull request courtesy Edgar
+    Ramírez-Mondragón.
index 00d5d0f2b3800da32376c5f11979cb7dc712fb7a..5f4485a8f7282567d921914d400aab10a4a507e0 100644 (file)
@@ -1958,6 +1958,9 @@ def attrsetter(attrname):
     return env["set"]
 
 
+_dunders = re.compile("^__.+__$")
+
+
 class TypingOnly:
     """A mixin class that marks a class as 'typing only', meaning it has
     absolutely no methods, attributes, or runtime functionality whatsoever.
@@ -1968,15 +1971,9 @@ class TypingOnly:
 
     def __init_subclass__(cls) -> None:
         if TypingOnly in cls.__bases__:
-            remaining = set(cls.__dict__).difference(
-                {
-                    "__module__",
-                    "__doc__",
-                    "__slots__",
-                    "__orig_bases__",
-                    "__annotations__",
-                }
-            )
+            remaining = {
+                name for name in cls.__dict__ if not _dunders.match(name)
+            }
             if remaining:
                 raise AssertionError(
                     f"Class {cls} directly inherits TypingOnly but has "