Skip to content

Commit

Permalink
Ignore all dunders when checking attributes in `sqlalchemy.util.langh…
Browse files Browse the repository at this point in the history
…elpers.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: #11335
Pull-request-sha: babd703

Change-Id: Ia2e7392c9403e25266c7d30b987b577f49d008c0
(cherry picked from commit eb118e2)
  • Loading branch information
edgarrmondragon authored and zzzeek committed Apr 30, 2024
1 parent ee41205 commit 53dc965
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
7 changes: 7 additions & 0 deletions doc/build/changelog/unreleased_20/11334.rst
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 6 additions & 9 deletions lib/sqlalchemy/util/langhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 "
Expand Down

0 comments on commit 53dc965

Please sign in to comment.