summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/lambdas.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-01-10 16:48:05 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-01-11 13:06:57 -0500
commit3a23e8ed29180e914883a263ec83373ecbd02efa (patch)
tree30775bf16114d0415d1b429dc4df1957e64cf082 /lib/sqlalchemy/sql/lambdas.py
parent5681d4e4da8ee69d83e9c0103c171d413d4c183e (diff)
downloadsqlalchemy-3a23e8ed29180e914883a263ec83373ecbd02efa.tar.gz
remove internal use of metaclasses
All but one metaclass used internally can now be replaced using __init_subclass__(). Within this patch we remove: * events._EventMeta * sql.visitors.TraversibleType * sql.visitors.InternalTraversibleType * testing.fixtures.FindFixture * testing.fixtures.FindFixtureDeclarative * langhelpers.EnsureKWArgType * sql.functions._GenericMeta * sql.type_api.VisitableCheckKWArg (was a mixture of TraversibleType and EnsureKWArgType) The remaining internal class is MetaOptions used by the sql.Options object which is in turn currently mostly for ORM internal use, as this type implements class level overrides for the ``+`` operator. For declarative, removing DeclarativeMeta in place of an `__init_subclass__()` class would not be fully feasible as it would break backwards compatibility with applications that refer to this class explicitly, but also DeclarativeMeta intercepts class-level attribute set and delete operations which is a widely used pattern. An option for declarative base to use `__init_subclass__()` should be provided but this is out of scope for this particular change. Change-Id: I8aa898c7ab59d887739037d34b1cbab36521ab78 References: #6810
Diffstat (limited to 'lib/sqlalchemy/sql/lambdas.py')
-rw-r--r--lib/sqlalchemy/sql/lambdas.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/sqlalchemy/sql/lambdas.py b/lib/sqlalchemy/sql/lambdas.py
index 2387e551e..d71c85d60 100644
--- a/lib/sqlalchemy/sql/lambdas.py
+++ b/lib/sqlalchemy/sql/lambdas.py
@@ -11,6 +11,7 @@ import operator
import types
import weakref
+from . import cache_key as _cache_key
from . import coercions
from . import elements
from . import roles
@@ -185,7 +186,7 @@ class LambdaElement(elements.ClauseElement):
else:
parent_closure_cache_key = ()
- if parent_closure_cache_key is not traversals.NO_CACHE:
+ if parent_closure_cache_key is not _cache_key.NO_CACHE:
anon_map = traversals.anon_map()
cache_key = tuple(
[
@@ -194,7 +195,7 @@ class LambdaElement(elements.ClauseElement):
]
)
- if traversals.NO_CACHE not in anon_map:
+ if _cache_key.NO_CACHE not in anon_map:
cache_key = parent_closure_cache_key + cache_key
self.closure_cache_key = cache_key
@@ -204,17 +205,17 @@ class LambdaElement(elements.ClauseElement):
except KeyError:
rec = None
else:
- cache_key = traversals.NO_CACHE
+ cache_key = _cache_key.NO_CACHE
rec = None
else:
- cache_key = traversals.NO_CACHE
+ cache_key = _cache_key.NO_CACHE
rec = None
self.closure_cache_key = cache_key
if rec is None:
- if cache_key is not traversals.NO_CACHE:
+ if cache_key is not _cache_key.NO_CACHE:
rec = AnalyzedFunction(
tracker, self, apply_propagate_attrs, fn
)
@@ -233,7 +234,7 @@ class LambdaElement(elements.ClauseElement):
self._rec = rec
- if cache_key is not traversals.NO_CACHE:
+ if cache_key is not _cache_key.NO_CACHE:
if self.parent_lambda is not None:
bindparams[:0] = self.parent_lambda._resolved_bindparams
@@ -326,8 +327,8 @@ class LambdaElement(elements.ClauseElement):
return expr
def _gen_cache_key(self, anon_map, bindparams):
- if self.closure_cache_key is traversals.NO_CACHE:
- anon_map[traversals.NO_CACHE] = True
+ if self.closure_cache_key is _cache_key.NO_CACHE:
+ anon_map[_cache_key.NO_CACHE] = True
return None
cache_key = (
@@ -808,7 +809,7 @@ class AnalyzedCode:
for tup_elem in opts.track_on[idx]
)
- elif isinstance(elem, traversals.HasCacheKey):
+ elif isinstance(elem, _cache_key.HasCacheKey):
def get(closure, opts, anon_map, bindparams):
return opts.track_on[idx]._gen_cache_key(anon_map, bindparams)
@@ -834,7 +835,7 @@ class AnalyzedCode:
"""
- if isinstance(cell_contents, traversals.HasCacheKey):
+ if isinstance(cell_contents, _cache_key.HasCacheKey):
def get(closure, opts, anon_map, bindparams):
@@ -1166,7 +1167,7 @@ class PyWrapper(ColumnOperators):
and not isinstance(
# TODO: coverage where an ORM option or similar is here
value,
- traversals.HasCacheKey,
+ _cache_key.HasCacheKey,
)
):
name = object.__getattribute__(self, "_name")