From d3a4e96196cd47858de072ae589c6554088edc24 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 22 Nov 2021 10:59:06 -0500 Subject: Support lightweight compiler column elements w/ slots the _CompileLabel class included ``__slots__`` but these weren't used as the superclasses included slots. Create a ``__slots__`` superclass for ``ClauseElement``, creating a new class of compilable SQL elements that don't include heavier features like caching, annotations and cloning, which are meant to be used only in an ad-hoc compiler fashion. Create new ``CompilerColumnElement`` from that which serves in column-oriented contexts, but similarly does not include any expression operator support as it is intended to be used only to generate a string. Apply this to both ``_CompileLabel`` as well as PostgreSQL ``_ColonCast``, which does not actually subclass ``ColumnElement`` as this class has memoized attributes that aren't worth changing, and does not include SQL operator capabilities as these are not needed for these compiler-only objects. this allows us to more inexpensively add new ad-hoc labels / casts etc. at compile time, as we will be seeking to expand out the typecasts that are needed for PostgreSQL dialects in a subsequent patch. Change-Id: I52973ae3295cb6e2eb0d7adc816c678a626643ed --- lib/sqlalchemy/sql/compiler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 482afb42f..29aa57faa 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -525,12 +525,12 @@ class TypeCompiler(util.with_metaclass(util.EnsureKWArgType, object)): # this was a Visitable, but to allow accurate detection of # column elements this is actually a column element -class _CompileLabel(elements.ColumnElement): +class _CompileLabel(elements.CompilerColumnElement): """lightweight label object which acts as an expression.Label.""" __visit_name__ = "label" - __slots__ = "element", "name" + __slots__ = "element", "name", "_alt_names" def __init__(self, col, name, alt_names=()): self.element = col -- cgit v1.2.1