From eda6dbbf387def2063d1b6719b64b20f9e7f2ab4 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Sat, 7 Mar 2020 19:17:07 +0100 Subject: 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 --- lib/sqlalchemy/sql/compiler.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 3ebcf24b0..b37c46216 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1022,9 +1022,10 @@ class SQLCompiler(Compiled): return expanded_state - @util.dependencies("sqlalchemy.engine.result") - def _create_result_map(self, result): + @util.preload_module("sqlalchemy.engine.result") + def _create_result_map(self): """utility method used for unit tests only.""" + result = util.preloaded.engine_result return result.CursorResultMetaData._create_description_match_map( self._result_columns ) @@ -4127,8 +4128,10 @@ class IdentifierPreparer(object): ident = self.quote_identifier(ident) return ident - @util.dependencies("sqlalchemy.sql.naming") - def format_constraint(self, naming, constraint, _alembic_quote=True): + @util.preload_module("sqlalchemy.sql.naming") + def format_constraint(self, constraint, _alembic_quote=True): + naming = util.preloaded.sql_naming + if isinstance(constraint.name, elements._defer_name): name = naming._constraint_name_for_table( constraint, constraint.table -- cgit v1.2.1