]> 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:06 +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

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 fe3bd1684053f15823382d16c391ef7207896edc..c97fa7d629a19c7baee547b65913cdcf7e7ef7fe 100644 (file)
@@ -1956,6 +1956,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.
@@ -1966,15 +1969,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 "