summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/base.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/base.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/base.py')
-rw-r--r--lib/sqlalchemy/sql/base.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py
index 74469b035..8ae8f8f65 100644
--- a/lib/sqlalchemy/sql/base.py
+++ b/lib/sqlalchemy/sql/base.py
@@ -17,6 +17,7 @@ from itertools import zip_longest
import operator
import re
import typing
+from typing import TypeVar
from . import roles
from . import visitors
@@ -571,11 +572,14 @@ class CompileState:
return decorate
+SelfGenerative = TypeVar("SelfGenerative", bound="Generative")
+
+
class Generative(HasMemoized):
"""Provide a method-chaining pattern in conjunction with the
@_generative decorator."""
- def _generate(self):
+ def _generate(self: SelfGenerative) -> SelfGenerative:
skip = self._memoized_keys
cls = self.__class__
s = cls.__new__(cls)
@@ -783,6 +787,8 @@ class Options(metaclass=_MetaOptions):
class CacheableOptions(Options, HasCacheKey):
+ __slots__ = ()
+
@hybridmethod
def _gen_cache_key(self, anon_map, bindparams):
return HasCacheKey._gen_cache_key(self, anon_map, bindparams)
@@ -797,6 +803,8 @@ class CacheableOptions(Options, HasCacheKey):
class ExecutableOption(HasCopyInternals):
+ __slots__ = ()
+
_annotations = util.EMPTY_DICT
__visit_name__ = "executable_option"