summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/util.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/orm/util.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/orm/util.py')
-rw-r--r--lib/sqlalchemy/orm/util.py49
1 files changed, 40 insertions, 9 deletions
diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py
index e84517670..75f711007 100644
--- a/lib/sqlalchemy/orm/util.py
+++ b/lib/sqlalchemy/orm/util.py
@@ -45,6 +45,7 @@ from ..sql import util as sql_util
from ..sql import visitors
from ..sql.annotation import SupportsCloneAnnotations
from ..sql.base import ColumnCollection
+from ..util.langhelpers import MemoizedSlots
all_cascades = frozenset(
@@ -609,8 +610,9 @@ class AliasedClass:
class AliasedInsp(
ORMEntityColumnsClauseRole,
ORMFromClauseRole,
- sql_base.MemoizedHasCacheKey,
+ sql_base.HasCacheKey,
InspectionAttr,
+ MemoizedSlots,
):
"""Provide an inspection interface for an
:class:`.AliasedClass` object.
@@ -650,6 +652,30 @@ class AliasedInsp(
"""
+ __slots__ = (
+ "__weakref__",
+ "_weak_entity",
+ "mapper",
+ "selectable",
+ "name",
+ "_adapt_on_names",
+ "with_polymorphic_mappers",
+ "polymorphic_on",
+ "_use_mapper_path",
+ "_base_alias",
+ "represents_outer_join",
+ "persist_selectable",
+ "local_table",
+ "_is_with_polymorphic",
+ "_with_polymorphic_entities",
+ "_adapter",
+ "_target",
+ "__clause_element__",
+ "_memoized_values",
+ "_all_column_expressions",
+ "_nest_adapters",
+ )
+
def __init__(
self,
entity,
@@ -738,8 +764,7 @@ class AliasedInsp(
is_aliased_class = True
"always returns True"
- @util.memoized_instancemethod
- def __clause_element__(self):
+ def _memoized_method___clause_element__(self):
return self.selectable._annotate(
{
"parentmapper": self.mapper,
@@ -863,8 +888,7 @@ class AliasedInsp(
else:
assert False, "mapper %s doesn't correspond to %s" % (mapper, self)
- @util.memoized_property
- def _get_clause(self):
+ def _memoized_attr__get_clause(self):
onclause, replacemap = self.mapper._get_clause
return (
self._adapter.traverse(onclause),
@@ -874,12 +898,10 @@ class AliasedInsp(
},
)
- @util.memoized_property
- def _memoized_values(self):
+ def _memoized_attr__memoized_values(self):
return {}
- @util.memoized_property
- def _all_column_expressions(self):
+ def _memoized_attr__all_column_expressions(self):
if self._is_with_polymorphic:
cols_plus_keys = self.mapper._columns_plus_keys(
[ent.mapper for ent in self._with_polymorphic_entities]
@@ -965,6 +987,15 @@ class LoaderCriteriaOption(CriteriaOption):
"""
+ __slots__ = (
+ "root_entity",
+ "entity",
+ "deferred_where_criteria",
+ "where_criteria",
+ "include_aliases",
+ "propagate_to_loaders",
+ )
+
_traverse_internals = [
("root_entity", visitors.ExtendedInternalTraversal.dp_plain_obj),
("entity", visitors.ExtendedInternalTraversal.dp_has_cache_key),