diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-10-06 21:46:03 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-10-06 22:25:23 -0400 |
| commit | f3268b6f2fa5ac7023f656caa085316fa46b24e9 (patch) | |
| tree | 8974b2d5345ef78d7025decbc314b03b71075818 /lib/sqlalchemy/util/langhelpers.py | |
| parent | 402cca8f2ac42a08fba7a200c4e1e086e2081aad (diff) | |
| download | sqlalchemy-f3268b6f2fa5ac7023f656caa085316fa46b24e9.tar.gz | |
Use preloaded for sql.util import in exc
Repaired a function-level import that was not using SQLAlchemy's standard
late-import system within the sqlalchemy.exc module.
Moved preloaded to sqlalchemy.util.preloaded so that it
does not depend on langhelpers which depends on exc.
Fixes: #5632
Change-Id: I61b7ce9cd461071ce543714739f67aa5aeb47fd6
Diffstat (limited to 'lib/sqlalchemy/util/langhelpers.py')
| -rw-r--r-- | lib/sqlalchemy/util/langhelpers.py | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 85a065e99..e546f196d 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -1044,53 +1044,6 @@ class MemoizedSlots(object): return self._fallback_getattr(key) -class _ModuleRegistry: - """Registry of modules to load in a package init file. - - To avoid potential thread safety issues for imports that are deferred - in a function, like https://bugs.python.org/issue38884, these modules - are added to the system module cache by importing them after the packages - has finished initialization. - - A global instance is provided under the name :attr:`.preloaded`. Use - the function :func:`.preload_module` to register modules to load and - :meth:`.import_prefix` to load all the modules that start with the - given path. - - While the modules are loaded in the global module cache, it's advisable - to access them using :attr:`.preloaded` to ensure that it was actually - registered. Each registered module is added to the instance ``__dict__`` - in the form `<package>_<module>`, omitting ``sqlalchemy`` from the package - name. Example: ``sqlalchemy.sql.util`` becomes ``preloaded.sql_util``. - """ - - def __init__(self, prefix="sqlalchemy"): - self.module_registry = set() - - def preload_module(self, *deps): - """Adds the specified modules to the list to load. - - This method can be used both as a normal function and as a decorator. - No change is performed to the decorated object. - """ - self.module_registry.update(deps) - return lambda fn: fn - - def import_prefix(self, path): - """Resolve all the modules in the registry that start with the - specified path. - """ - for module in self.module_registry: - key = module.split("sqlalchemy.")[-1].replace(".", "_") - if module.startswith(path) and key not in self.__dict__: - compat.import_(module, globals(), locals()) - self.__dict__[key] = sys.modules[module] - - -preloaded = _ModuleRegistry() -preload_module = preloaded.preload_module - - # from paste.deploy.converters def asbool(obj): if isinstance(obj, compat.string_types): |
