diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-04-28 16:19:43 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-05-03 15:58:45 -0400 |
| commit | 1fa3e2e3814b4d28deca7426bb3f36e7fb515496 (patch) | |
| tree | 9b07b8437b1190227c2e8c51f2e942936721000f /lib/sqlalchemy/sql | |
| parent | 6a496a5f40efe6d58b09eeca9320829789ceaa54 (diff) | |
| download | sqlalchemy-1fa3e2e3814b4d28deca7426bb3f36e7fb515496.tar.gz | |
pep484: attributes and related
also implements __slots__ for QueryableAttribute,
InstrumentedAttribute, Relationship.Comparator.
Change-Id: I47e823160706fc35a616f1179a06c7864089e5b5
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/base.py | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/cache_key.py | 8 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/util.py | 11 |
3 files changed, 20 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py index fb959654f..248b48a25 100644 --- a/lib/sqlalchemy/sql/base.py +++ b/lib/sqlalchemy/sql/base.py @@ -133,6 +133,8 @@ class Immutable: """ + __slots__ = () + _is_immutable = True def unique_params(self, *optionaldict, **kwargs): @@ -145,7 +147,7 @@ class Immutable: return self def _copy_internals( - self, omit_attrs: Iterable[str] = (), **kw: Any + self, *, omit_attrs: Iterable[str] = (), **kw: Any ) -> None: pass diff --git a/lib/sqlalchemy/sql/cache_key.py b/lib/sqlalchemy/sql/cache_key.py index 15fbc2afb..c16fbdae1 100644 --- a/lib/sqlalchemy/sql/cache_key.py +++ b/lib/sqlalchemy/sql/cache_key.py @@ -36,7 +36,6 @@ if typing.TYPE_CHECKING: from .elements import BindParameter from .elements import ClauseElement from .visitors import _TraverseInternalsType - from ..engine.base import _CompiledCacheType from ..engine.interfaces import _CoreSingleExecuteParams @@ -393,6 +392,13 @@ class MemoizedHasCacheKey(HasCacheKey, HasMemoized): return HasCacheKey._generate_cache_key(self) +class SlotsMemoizedHasCacheKey(HasCacheKey, util.MemoizedSlots): + __slots__ = () + + def _memoized_method__generate_cache_key(self) -> Optional[CacheKey]: + return HasCacheKey._generate_cache_key(self) + + class CacheKey(NamedTuple): """The key used to identify a SQL statement construct in the SQL compilation cache. diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 2e0112f08..2655adbdc 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -1265,7 +1265,16 @@ class ColumnAdapter(ClauseAdapter): if self.adapt_required and c is col: return None - c._allow_label_resolve = self.allow_label_resolve + # allow_label_resolve is consumed by one case for joined eager loading + # as part of its logic to prevent its own columns from being affected + # by .order_by(). Before full typing were applied to the ORM, this + # logic would set this attribute on the incoming object (which is + # typically a column, but we have a test for it being a non-column + # object) if no column were found. While this seemed to + # have no negative effects, this adjustment should only occur on the + # new column which is assumed to be local to an adapted selectable. + if c is not col: + c._allow_label_resolve = self.allow_label_resolve return c |
