summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/cache_key.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-01-18 17:00:16 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-01-21 11:46:51 -0500
commitd46a4c0326bd2e697794514b920e6727d5153324 (patch)
treeb3368bc6d402148d46317b4532db6b92352bd666 /lib/sqlalchemy/sql/cache_key.py
parent7d9b811555a88dd2f1cb1520027546b87383e159 (diff)
downloadsqlalchemy-d46a4c0326bd2e697794514b920e6727d5153324.tar.gz
Add new infrastructure to support greater use of __slots__
* Changed AliasedInsp to use __slots__ * Migrated all of strategy_options to use __slots__ for objects. Adds new infrastructure to traversals to support shallow copy, to dict and from dict based on internal traversal attributes. Load / _LoadElement then leverage this to provide clone / generative / getstate without the need for __dict__ or explicit attribute lists. Doing this change revealed that there are lots of things that trigger off of whether or not a class has a __visit_name__ attribute. so to suit that we've gone back to having Visitable, which is a better name than Traversible at this point (I think Traversible is mis-spelled too). Change-Id: I13d04e494339fac9dbda0b8e78153418abebaf72 References: #7527
Diffstat (limited to 'lib/sqlalchemy/sql/cache_key.py')
-rw-r--r--lib/sqlalchemy/sql/cache_key.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/cache_key.py b/lib/sqlalchemy/sql/cache_key.py
index 8dd44dbf0..42bd60353 100644
--- a/lib/sqlalchemy/sql/cache_key.py
+++ b/lib/sqlalchemy/sql/cache_key.py
@@ -47,6 +47,11 @@ class CacheTraverseTarget(enum.Enum):
class HasCacheKey:
"""Mixin for objects which can produce a cache key.
+ This class is usually in a hierarchy that starts with the
+ :class:`.HasTraverseInternals` base, but this is optional. Currently,
+ the class should be able to work on its own without including
+ :class:`.HasTraverseInternals`.
+
.. seealso::
:class:`.CacheKey`
@@ -55,6 +60,8 @@ class HasCacheKey:
"""
+ __slots__ = ()
+
_cache_key_traversal = NO_CACHE
_is_has_cache_key = True
@@ -106,11 +113,17 @@ class HasCacheKey:
_cache_key_traversal = getattr(cls, "_cache_key_traversal", None)
if _cache_key_traversal is None:
try:
+ # this would be HasTraverseInternals
_cache_key_traversal = cls._traverse_internals
except AttributeError:
cls._generated_cache_key_traversal = NO_CACHE
return NO_CACHE
+ assert _cache_key_traversal is not NO_CACHE, (
+ f"class {cls} has _cache_key_traversal=NO_CACHE, "
+ "which conflicts with inherit_cache=True"
+ )
+
# TODO: wouldn't we instead get this from our superclass?
# also, our superclass may not have this yet, but in any case,
# we'd generate for the superclass that has it. this is a little
@@ -323,6 +336,8 @@ class HasCacheKey:
class MemoizedHasCacheKey(HasCacheKey, HasMemoized):
+ __slots__ = ()
+
@HasMemoized.memoized_instancemethod
def _generate_cache_key(self):
return HasCacheKey._generate_cache_key(self)