From eb118e23a29a29469edb4c1927250f4b726de68e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Edgar=20Ram=C3=ADrez-Mondrag=C3=B3n?= Date: Mon, 29 Apr 2024 21:53:07 -0400 Subject: [PATCH] Ignore all dunders when checking attributes in `sqlalchemy.util.langhelpers.TypingOnly` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 7 +++++++ lib/sqlalchemy/util/langhelpers.py | 15 ++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 doc/build/changelog/unreleased_20/11334.rst 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 fe3bd16840..c97fa7d629 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -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 " -- 2.47.2