From: Edgar Ramírez-Mondragón Date: Tue, 30 Apr 2024 01:53:07 +0000 (-0400) Subject: Ignore all dunders when checking attributes in `sqlalchemy.util.langhelpers.TypingOnly` X-Git-Tag: rel_2_0_30~11^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53dc9653fbdf5b68f540db7fdea875a6b8e07b41;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Ignore all dunders when checking attributes in `sqlalchemy.util.langhelpers.TypingOnly` 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) --- diff --git a/doc/build/changelog/unreleased_20/11334.rst b/doc/build/changelog/unreleased_20/11334.rst new file mode 100644 index 0000000000..48f590c4ac --- /dev/null +++ b/doc/build/changelog/unreleased_20/11334.rst @@ -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. diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 00d5d0f2b3..5f4485a8f7 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -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 "