summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/schema.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/schema.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/schema.py')
-rw-r--r--lib/sqlalchemy/sql/schema.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index 4c627c4cc..69f60ba24 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -2193,8 +2193,10 @@ class ColumnDefault(DefaultGenerator):
)
@util.memoized_property
- @util.dependencies("sqlalchemy.sql.sqltypes")
- def _arg_is_typed(self, sqltypes):
+ @util.preload_module("sqlalchemy.sql.sqltypes")
+ def _arg_is_typed(self):
+ sqltypes = util.preloaded.sql_sqltypes
+
if self.is_clause_element:
return not isinstance(self.arg.type, sqltypes.NullType)
else:
@@ -2440,14 +2442,16 @@ class Sequence(roles.StatementRole, DefaultGenerator):
def is_clause_element(self):
return False
- @util.dependencies("sqlalchemy.sql.functions.func")
- def next_value(self, func):
+ @util.preload_module("sqlalchemy.sql.functions")
+ def next_value(self):
"""Return a :class:`.next_value` function element
which will render the appropriate increment function
for this :class:`.Sequence` within any SQL expression.
"""
- return func.next_value(self, bind=self.bind)
+ return util.preloaded.sql_functions.func.next_value(
+ self, bind=self.bind
+ )
def _set_parent(self, column):
super(Sequence, self)._set_parent(column)
@@ -3925,10 +3929,10 @@ class MetaData(SchemaItem):
"""
return self._bind
- @util.dependencies("sqlalchemy.engine.url")
- def _bind_to(self, url, bind):
+ @util.preload_module("sqlalchemy.engine.url")
+ def _bind_to(self, bind):
"""Bind this MetaData to an Engine, Connection, string or URL."""
-
+ url = util.preloaded.engine_url
if isinstance(bind, util.string_types + (url.URL,)):
self._bind = sqlalchemy.create_engine(bind)
else:
@@ -4231,10 +4235,10 @@ class ThreadLocalMetaData(MetaData):
return getattr(self.context, "_engine", None)
- @util.dependencies("sqlalchemy.engine.url")
- def _bind_to(self, url, bind):
+ @util.preload_module("sqlalchemy.engine.url")
+ def _bind_to(self, bind):
"""Bind to a Connectable in the caller's thread."""
-
+ url = util.preloaded.engine_url
if isinstance(bind, util.string_types + (url.URL,)):
try:
self.context._engine = self.__engines[bind]