summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/elements.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2020-03-07 19:17:07 +0100
committerMike Bayer <mike_mp@zzzcomputing.com>2020-03-07 17:50:45 -0500
commiteda6dbbf387def2063d1b6719b64b20f9e7f2ab4 (patch)
tree4af5f41edfac169b0fdc6d6cab0fce4e8bf776cf /lib/sqlalchemy/sql/elements.py
parent851fb8f5a661c66ee76308181118369c8c4df9e0 (diff)
downloadsqlalchemy-eda6dbbf387def2063d1b6719b64b20f9e7f2ab4.tar.gz
Simplified module pre-loading strategy and made it linter friendly
Introduced a modules registry to register modules that should be lazily loaded in the package init. This ensures that they are in the system module cache, avoiding potential thread safety issues as when importing them directly in the function that uses them. The module registry is used to obtain these modules directly, ensuring that the all the lazily loaded modules are resolved at the proper time This replaces dependency_for decorator and the dependencies decorator logic, removing the need to pass the resolved modules as arguments of the decodated functions and removes possible errors caused by linters. Fixes: #4689 Fixes: #4656 Change-Id: I2e291eba4297867fc0ddb5d875b9f7af34751d01
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r--lib/sqlalchemy/sql/elements.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index 47739a37d..bb68e8a7e 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -422,8 +422,8 @@ class ClauseElement(
return self
- @util.dependencies("sqlalchemy.engine.default")
- def compile(self, default, bind=None, dialect=None, **kw):
+ @util.preload_module("sqlalchemy.engine.default")
+ def compile(self, bind=None, dialect=None, **kw):
"""Compile this SQL expression.
The return value is a :class:`~.Compiled` object.
@@ -477,6 +477,7 @@ class ClauseElement(
"""
+ default = util.preloaded.engine_default
if not dialect:
if bind:
dialect = bind.dialect
@@ -1782,8 +1783,8 @@ class TextClause(
else:
new_params[key] = existing._with_value(value)
- @util.dependencies("sqlalchemy.sql.selectable")
- def columns(self, selectable, *cols, **types):
+ @util.preload_module("sqlalchemy.sql.selectable")
+ def columns(self, *cols, **types):
r"""Turn this :class:`.TextClause` object into a
:class:`.TextualSelect` object that serves the same role as a SELECT
statement.
@@ -1888,6 +1889,7 @@ class TextClause(
argument as it also indicates positional ordering.
"""
+ selectable = util.preloaded.sql_selectable
positional_input_cols = [
ColumnClause(col.key, types.pop(col.key))
if col.key in types