From af4285e6adf2a052ce985f9d3d97cc89778fca96 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 13 Nov 2010 13:19:36 -0500 Subject: - move inline "import" statements to use new "util.importlater()" construct. cuts down on clutter, timeit says there's a teeny performance gain, at least where the access is compared against attr.subattr. these aren't super-critical calls anyway - slight inlining in _class_to_mapper --- lib/sqlalchemy/schema.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'lib/sqlalchemy/schema.py') diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 069e58ced..8e937968d 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -32,7 +32,9 @@ import re, inspect from sqlalchemy import exc, util, dialects from sqlalchemy.sql import expression, visitors -URL = None +sqlutil = util.importlater("sqlalchemy.sql", "util") +url = util.importlater("sqlalchemy.engine", "url") + __all__ = ['SchemaItem', 'Table', 'Column', 'ForeignKey', 'Sequence', 'Index', 'ForeignKeyConstraint', 'PrimaryKeyConstraint', 'CheckConstraint', @@ -1979,11 +1981,7 @@ class MetaData(SchemaItem): def _bind_to(self, bind): """Bind this MetaData to an Engine, Connection, string or URL.""" - global URL - if URL is None: - from sqlalchemy.engine.url import URL - - if isinstance(bind, (basestring, URL)): + if isinstance(bind, (basestring, url.URL)): from sqlalchemy import create_engine self._bind = create_engine(bind) else: @@ -2007,8 +2005,7 @@ class MetaData(SchemaItem): """Returns a list of ``Table`` objects sorted in order of dependency. """ - from sqlalchemy.sql.util import sort_tables - return sort_tables(self.tables.itervalues()) + return sqlutil.sort_tables(self.tables.itervalues()) def reflect(self, bind=None, schema=None, views=False, only=None): """Load all available table definitions from the database. @@ -2205,11 +2202,7 @@ class ThreadLocalMetaData(MetaData): def _bind_to(self, bind): """Bind to a Connectable in the caller's thread.""" - global URL - if URL is None: - from sqlalchemy.engine.url import URL - - if isinstance(bind, (basestring, URL)): + if isinstance(bind, (basestring, url.URL)): try: self.context._engine = self.__engines[bind] except KeyError: -- cgit v1.2.1