diff options
27 files changed, 164 insertions, 128 deletions
diff --git a/lib/sqlalchemy/engine/__init__.py b/lib/sqlalchemy/engine/__init__.py index eab8b3c0b..d3802f306 100644 --- a/lib/sqlalchemy/engine/__init__.py +++ b/lib/sqlalchemy/engine/__init__.py @@ -180,8 +180,9 @@ def engine_from_config(configuration, prefix='sqlalchemy.', **kwargs): def _coerce_config(configuration, prefix): """Convert configuration values to expected types.""" - options = dict([(key[len(prefix):], configuration[key]) - for key in configuration if key.startswith(prefix)]) + options = dict((key[len(prefix):], configuration[key]) + for key in configuration + if key.startswith(prefix)) for option, type_ in ( ('convert_unicode', bool), ('pool_timeout', int), diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index f356a7c05..6aafafdc1 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -1346,8 +1346,8 @@ class RowProxy(object): def __eq__(self, other): return ((other is self) or - (other == tuple([self.__parent._get_col(self.__row, key) - for key in xrange(len(self.__row))]))) + (other == tuple(self.__parent._get_col(self.__row, key) + for key in xrange(len(self.__row))))) def __ne__(self, other): return not self.__eq__(other) @@ -1489,7 +1489,8 @@ class ResultProxy(object): self.__props[o] = rec if self.__echo: - self.context.engine.logger.debug("Col " + repr(tuple([x[0] for x in metadata]))) + self.context.engine.logger.debug( + "Col " + repr(tuple(x[0] for x in metadata))) def _create_key_cache(self): # local copies to avoid circular ref against 'self' @@ -1622,7 +1623,7 @@ class ResultProxy(object): # so we use an exception catch to reduce conditionals in _get_col if isinstance(key, slice): indices = key.indices(len(row)) - return tuple([self._get_col(row, i) for i in xrange(*indices)]) + return tuple(self._get_col(row, i) for i in xrange(*indices)) else: raise @@ -1773,7 +1774,7 @@ class BufferedColumnResultProxy(ResultProxy): # so we use an exception catch to reduce conditionals in _get_col if isinstance(key, slice): indices = key.indices(len(row)) - return tuple([self._get_col(row, i) for i in xrange(*indices)]) + return tuple(self._get_col(row, i) for i in xrange(*indices)) else: raise diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index dcbf8c76f..b68ce0818 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -136,14 +136,12 @@ class DefaultExecutionContext(base.ExecutionContext): # compiled clauseelement. process bind params, process table defaults, # track collections used by ResultProxy to target and process results - self.processors = dict([ + self.processors = dict( (key, value) for key, value in - [( - compiled.bind_names[bindparam], - bindparam.bind_processor(self.dialect) - ) for bindparam in compiled.bind_names] - if value is not None - ]) + ( (compiled.bind_names[bindparam], + bindparam.bind_processor(self.dialect)) + for bindparam in compiled.bind_names ) + if value is not None) self.result_map = compiled.result_map @@ -212,7 +210,7 @@ class DefaultExecutionContext(base.ExecutionContext): # that doesnt specify positional (because of execute_text()) if not isinstance(d, dict): return d - return dict([(k.encode(self.dialect.encoding), d[k]) for k in d]) + return dict((k.encode(self.dialect.encoding), d[k]) for k in d) return [proc(d) for d in params] or [{}] def __convert_compiled_params(self, compiled_parameters): @@ -315,10 +313,9 @@ class DefaultExecutionContext(base.ExecutionContext): from the bind parameter's ``TypeEngine`` objects. """ - types = dict([ + types = dict( (self.compiled.bind_names[bindparam], bindparam.type) - for bindparam in self.compiled.bind_names - ]) + for bindparam in self.compiled.bind_names) if self.dialect.positional: inputsizes = [] diff --git a/lib/sqlalchemy/engine/strategies.py b/lib/sqlalchemy/engine/strategies.py index aa595c8e3..c9e65982e 100644 --- a/lib/sqlalchemy/engine/strategies.py +++ b/lib/sqlalchemy/engine/strategies.py @@ -115,7 +115,7 @@ class DefaultEngineStrategy(EngineStrategy): "Invalid argument(s) %s sent to create_engine(), " "using configuration %s/%s/%s. Please check that the " "keyword arguments are appropriate for this combination " - "of components." % (','.join(["'%s'" % k for k in kwargs]), + "of components." % (','.join("'%s'" % k for k in kwargs), dialect.__class__.__name__, pool.__class__.__name__, engineclass.__name__)) diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index 72d09bf85..b81a91d59 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -72,7 +72,7 @@ class URL(object): if self.query: keys = self.query.keys() keys.sort() - s += '?' + "&".join(["%s=%s" % (k, self.query[k]) for k in keys]) + s += '?' + "&".join("%s=%s" % (k, self.query[k]) for k in keys) return s def __eq__(self, other): @@ -169,7 +169,7 @@ def _parse_rfc1738_args(name): components['database'] = tokens[0] query = (len(tokens) > 1 and dict(cgi.parse_qsl(tokens[1]))) or None if query is not None: - query = dict([(k.encode('ascii'), query[k]) for k in query]) + query = dict((k.encode('ascii'), query[k]) for k in query) else: query = None components['query'] = query diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py index 602ef9408..96c2e4177 100644 --- a/lib/sqlalchemy/exc.py +++ b/lib/sqlalchemy/exc.py @@ -126,8 +126,8 @@ class DBAPIError(SQLAlchemyError): self.connection_invalidated = connection_invalidated def __str__(self): - return ' '.join([SQLAlchemyError.__str__(self), - repr(self.statement), repr(self.params)]) + return ' '.join((SQLAlchemyError.__str__(self), + repr(self.statement), repr(self.params))) # As of 0.4, SQLError is now DBAPIError. diff --git a/lib/sqlalchemy/ext/sqlsoup.py b/lib/sqlalchemy/ext/sqlsoup.py index 1e7ee8184..9364f8ae7 100644 --- a/lib/sqlalchemy/ext/sqlsoup.py +++ b/lib/sqlalchemy/ext/sqlsoup.py @@ -432,7 +432,7 @@ def _selectable_name(selectable): if isinstance(selectable, sql.Alias): return _selectable_name(selectable.element) elif isinstance(selectable, sql.Select): - return ''.join([_selectable_name(s) for s in selectable.froms]) + return ''.join(_selectable_name(s) for s in selectable.froms) elif isinstance(selectable, schema.Table): return selectable.name.capitalize() else: diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index c6c1860ea..9009e4c4f 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -877,11 +877,12 @@ class InstanceState(object): def unmodified(self): """a set of keys which have no uncommitted changes""" - return util.Set([ - key for key in self.manager.keys() if - key not in self.committed_state - or (key in self.manager.mutable_attributes and not self.manager[key].impl.check_mutable_modified(self)) - ]) + return util.Set( + key for key in self.manager.keys() + if (key not in self.committed_state or + (key in self.manager.mutable_attributes and + not self.manager[key].impl.check_mutable_modified(self)))) + unmodified = property(unmodified) def unloaded(self): @@ -891,10 +892,10 @@ class InstanceState(object): was never populated or modified. """ - return util.Set([ - key for key in self.manager.keys() if - key not in self.committed_state and key not in self.dict - ]) + return util.Set( + key for key in self.manager.keys() + if key not in self.committed_state and key not in self.dict) + unloaded = property(unloaded) def expire_attributes(self, attribute_names): diff --git a/lib/sqlalchemy/orm/collections.py b/lib/sqlalchemy/orm/collections.py index fb1d18895..aed206957 100644 --- a/lib/sqlalchemy/orm/collections.py +++ b/lib/sqlalchemy/orm/collections.py @@ -146,8 +146,8 @@ def column_mapped_collection(mapping_spec): def keyfunc(value): state = instance_state(value) m = _state_mapper(state) - return tuple([m._get_state_attr_by_column(state, c) - for c in mapping_spec]) + return tuple(m._get_state_attr_by_column(state, c) + for c in mapping_spec) return lambda: MappedCollection(keyfunc) def attribute_mapped_collection(attr_name): diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py index ec0bb4d09..54208484b 100644 --- a/lib/sqlalchemy/orm/dependency.py +++ b/lib/sqlalchemy/orm/dependency.py @@ -279,7 +279,7 @@ class DetectKeySwitch(DependencyProcessor): self._process_key_switches(deplist, uowcommit) def _process_key_switches(self, deplist, uowcommit): - switchers = util.Set([s for s in deplist if self._pks_changed(uowcommit, s)]) + switchers = util.Set(s for s in deplist if self._pks_changed(uowcommit, s)) if switchers: # yes, we're doing a linear search right now through the UOW. only # takes effect when primary key values have actually changed. @@ -502,7 +502,7 @@ class MapperStub(object): self._inheriting_mappers = [] def polymorphic_iterator(self): - return iter([self]) + return iter((self,)) def _register_dependencies(self, uowcommit): pass diff --git a/lib/sqlalchemy/orm/evaluator.py b/lib/sqlalchemy/orm/evaluator.py index 30d2e8aed..2fbf3eac4 100644 --- a/lib/sqlalchemy/orm/evaluator.py +++ b/lib/sqlalchemy/orm/evaluator.py @@ -6,15 +6,15 @@ import operator class UnevaluatableError(Exception): pass -_straight_ops = Set([getattr(operators, op) for op in [ - 'add', 'mul', 'sub', 'div', 'mod', 'truediv', 'lt', 'le', 'ne', 'gt', 'ge', 'eq' -]]) +_straight_ops = Set(getattr(operators, op) + for op in ('add', 'mul', 'sub', 'div', 'mod', 'truediv', + 'lt', 'le', 'ne', 'gt', 'ge', 'eq')) -_notimplemented_ops = Set([getattr(operators, op) for op in [ - 'like_op', 'notlike_op', 'ilike_op', 'notilike_op', 'between_op', 'in_op', 'notin_op', - 'endswith_op', 'concat_op', -]]) +_notimplemented_ops = Set(getattr(operators, op) + for op in ('like_op', 'notlike_op', 'ilike_op', + 'notilike_op', 'between_op', 'in_op', + 'notin_op', 'endswith_op', 'concat_op')) class EvaluatorCompiler(object): def process(self, clause): diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index 96a6e340c..7d0bae1da 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -368,7 +368,7 @@ class MapperProperty(object): See PropertyLoader for the related instance implementation. """ - return iter([]) + return iter(()) def set_parent(self, parent): self.parent = parent diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 6196682dd..97bf6644f 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -510,7 +510,7 @@ class Mapper(object): self._cols_by_table = {} all_cols = util.Set(chain(*[col.proxy_set for col in self._columntoproperty])) - pk_cols = util.Set([c for c in all_cols if c.primary_key]) + pk_cols = util.Set(c for c in all_cols if c.primary_key) # identify primary key columns which are also mapped by this mapper. for t in util.Set(self.tables + [self.mapped_table]): @@ -519,15 +519,14 @@ class Mapper(object): # ordering is important since it determines the ordering of mapper.primary_key (and therefore query.get()) self._pks_by_table[t] = util.OrderedSet(t.primary_key).intersection(pk_cols) self._cols_by_table[t] = util.OrderedSet(t.c).intersection(all_cols) - - # determine cols that aren't expressed within our tables; - # mark these as "read only" properties which are refreshed upon - # INSERT/UPDATE - self._readonly_props = util.Set([ - self._columntoproperty[col] for col in self._columntoproperty if - not hasattr(col, 'table') or col.table not in self._cols_by_table - ]) - + + # determine cols that aren't expressed within our tables; mark these + # as "read only" properties which are refreshed upon INSERT/UPDATE + self._readonly_props = util.Set( + self._columntoproperty[col] + for col in self._columntoproperty + if not hasattr(col, 'table') or col.table not in self._cols_by_table) + # if explicit PK argument sent, add those columns to the primary key mappings if self.primary_key_argument: for k in self.primary_key_argument: @@ -544,9 +543,12 @@ class Mapper(object): else: # determine primary key from argument or mapped_table pks - reduce to the minimal set of columns if self.primary_key_argument: - primary_key = sqlutil.reduce_columns([self.mapped_table.corresponding_column(c) for c in self.primary_key_argument]) + primary_key = sqlutil.reduce_columns( + self.mapped_table.corresponding_column(c) + for c in self.primary_key_argument) else: - primary_key = sqlutil.reduce_columns(self._pks_by_table[self.mapped_table]) + primary_key = sqlutil.reduce_columns( + self._pks_by_table[self.mapped_table]) if len(primary_key) == 0: raise sa_exc.ArgumentError("Mapper %s could not assemble any primary key columns for mapped table '%s'" % (self, self.mapped_table.description)) diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index b6f1c803f..76bcde0dc 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -638,9 +638,9 @@ class PropertyLoader(StrategizedProperty): else: self.secondary_synchronize_pairs = None - self._foreign_keys = util.Set([r for l, r in self.synchronize_pairs]) + self._foreign_keys = util.Set(r for l, r in self.synchronize_pairs) if self.secondary_synchronize_pairs: - self._foreign_keys.update([r for l, r in self.secondary_synchronize_pairs]) + self._foreign_keys.update(r for l, r in self.secondary_synchronize_pairs) def _determine_direction(self): if self.secondaryjoin is not None: @@ -726,9 +726,9 @@ class PropertyLoader(StrategizedProperty): if log.is_info_enabled(self.logger): self.logger.info(str(self) + " setup primary join %s" % self.primaryjoin) self.logger.info(str(self) + " setup secondary join %s" % self.secondaryjoin) - self.logger.info(str(self) + " synchronize pairs [%s]" % ",".join(["(%s => %s)" % (l, r) for l, r in self.synchronize_pairs])) - self.logger.info(str(self) + " secondary synchronize pairs [%s]" % ",".join(["(%s => %s)" % (l, r) for l, r in self.secondary_synchronize_pairs or []])) - self.logger.info(str(self) + " local/remote pairs [%s]" % ",".join(["(%s / %s)" % (l, r) for l, r in self.local_remote_pairs])) + self.logger.info(str(self) + " synchronize pairs [%s]" % ",".join("(%s => %s)" % (l, r) for l, r in self.synchronize_pairs)) + self.logger.info(str(self) + " secondary synchronize pairs [%s]" % ",".join(("(%s => %s)" % (l, r) for l, r in self.secondary_synchronize_pairs or []))) + self.logger.info(str(self) + " local/remote pairs [%s]" % ",".join("(%s / %s)" % (l, r) for l, r in self.local_remote_pairs)) self.logger.info(str(self) + " relation direction %s" % self.direction) if self.uselist is None and self.direction is MANYTOONE: diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index c9b2dd9aa..6bc1ce7fe 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -445,7 +445,7 @@ class Query(object): query_from_parent = classmethod(util.deprecated(None, False)(query_from_parent)) def correlate(self, *args): - self._correlate = self._correlate.union([_orm_selectable(s) for s in args]) + self._correlate = self._correlate.union(_orm_selectable(s) for s in args) correlate = _generative()(correlate) def autoflush(self, setting): @@ -1078,7 +1078,9 @@ class Query(object): (process, labels) = zip(*[query_entity.row_processor(self, context, custom_rows) for query_entity in self._entities]) if not single_entity: - labels = dict([(label, property(util.itemgetter(i))) for i, label in enumerate(labels) if label]) + labels = dict((label, property(util.itemgetter(i))) + for i, label in enumerate(labels) + if label) rowtuple = type.__new__(type, "RowTuple", (tuple,), labels) rowtuple.keys = labels.keys @@ -1100,7 +1102,8 @@ class Query(object): elif single_entity: rows = [process[0](context, row) for row in fetch] else: - rows = [rowtuple([proc(context, row) for proc in process]) for row in fetch] + rows = [rowtuple(proc(context, row) for proc in process) + for row in fetch] if filter: rows = filter(rows) @@ -1160,7 +1163,7 @@ class Query(object): try: params[_get_params[primary_key].key] = ident[i] except IndexError: - raise sa_exc.InvalidRequestError("Could not find enough values to formulate primary key for query.get(); primary key columns are %s" % ', '.join(["'%s'" % str(c) for c in q.mapper.primary_key])) + raise sa_exc.InvalidRequestError("Could not find enough values to formulate primary key for query.get(); primary key columns are %s" % ', '.join("'%s'" % str(c) for c in q.mapper.primary_key)) q._params = params if lockmode is not None: @@ -1444,7 +1447,9 @@ class Query(object): """ for entity, (mapper, adapter, s, i, w) in self._mapper_adapter_map.iteritems(): if mapper.single and mapper.inherits and mapper.polymorphic_on and mapper.polymorphic_identity is not None: - crit = mapper.polymorphic_on.in_([m.polymorphic_identity for m in mapper.polymorphic_iterator()]) + crit = mapper.polymorphic_on.in_( + m.polymorphic_identity + for m in mapper.polymorphic_iterator()) if adapter: crit = adapter.traverse(crit) crit = self._adapt_clause(crit, False, False) @@ -1625,10 +1630,10 @@ class _ColumnEntity(_QueryEntity): self.column = column self.entity_name = None self.froms = util.Set() - self.entities = util.OrderedSet([ - elem._annotations['parententity'] for elem in visitors.iterate(column, {}) - if 'parententity' in elem._annotations - ]) + self.entities = util.OrderedSet( + elem._annotations['parententity'] + for elem in visitors.iterate(column, {}) + if 'parententity' in elem._annotations) if self.entities: self.entity_zero = list(self.entities)[0] diff --git a/lib/sqlalchemy/orm/scoping.py b/lib/sqlalchemy/orm/scoping.py index d551bc9bc..aa79e610f 100644 --- a/lib/sqlalchemy/orm/scoping.py +++ b/lib/sqlalchemy/orm/scoping.py @@ -59,9 +59,9 @@ class ScopedSession(object): from sqlalchemy.orm import mapper - extension_args = dict([(arg, kwargs.pop(arg)) - for arg in get_cls_kwargs(_ScopedExt) - if arg in kwargs]) + extension_args = dict((arg, kwargs.pop(arg)) + for arg in get_cls_kwargs(_ScopedExt) + if arg in kwargs) kwargs['extension'] = extension = to_list(kwargs.get('extension', [])) if extension_args: diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index 3073e17db..c58a04547 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -475,7 +475,7 @@ class LazyLoader(AbstractRelationLoader): secondaryjoin = visitors.replacement_traverse(secondaryjoin, {}, col_to_bind) lazywhere = sql.and_(lazywhere, secondaryjoin) - bind_to_col = dict([(binds[col].key, col) for col in binds]) + bind_to_col = dict((binds[col].key, col) for col in binds) return (lazywhere, bind_to_col, equated_columns) _create_lazy_clause = classmethod(_create_lazy_clause) diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index 4edfeefdc..ec3275f06 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -310,7 +310,9 @@ class UOWTransaction(object): ret.append(task) if self._should_log_debug: - self.logger.debug("Dependent tuples:\n" + "\n".join(["(%s->%s)" % (d[0].class_.__name__, d[1].class_.__name__) for d in self.dependencies])) + self.logger.debug("Dependent tuples:\n" + "\n".join( + "(%s->%s)" % (d[0].class_.__name__, d[1].class_.__name__) + for d in self.dependencies)) self.logger.debug("Dependency sort:\n"+ str(ret)) return ret diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 46d527d06..e600694e0 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -12,8 +12,9 @@ from sqlalchemy.sql import expression, util as sql_util, operators from sqlalchemy.orm.interfaces import MapperExtension, EXT_CONTINUE, PropComparator, MapperProperty from sqlalchemy.orm import attributes, exc -all_cascades = util.FrozenSet(["delete", "delete-orphan", "all", "merge", - "expunge", "save-update", "refresh-expire", "none"]) +all_cascades = util.FrozenSet(("delete", "delete-orphan", "all", "merge", + "expunge", "save-update", "refresh-expire", + "none")) _INSTRUMENTOR = ('mapper', 'instrumentor') @@ -21,7 +22,7 @@ class CascadeOptions(object): """Keeps track of the options sent to relation().cascade""" def __init__(self, arg=""): - values = util.Set([c.strip() for c in arg.split(',')]) + values = util.Set(c.strip() for c in arg.split(',')) self.delete_orphan = "delete-orphan" in values self.delete = "delete" in values or "all" in values self.save_update = "save-update" in values or "all" in values @@ -79,7 +80,8 @@ def polymorphic_union(table_map, typecolname, aliasname='p_union'): [sql.literal_column("'%s'" % type).label(typecolname)], from_obj=[table])) else: - result.append(sql.select([col(name, table) for name in colnames], from_obj=[table])) + result.append(sql.select([col(name, table) for name in colnames], + from_obj=[table])) return sql.union_all(*result).alias(aliasname) def identity_key(*args, **kwargs): @@ -159,8 +161,8 @@ class ExtensionCarrier(object): """ - interface = util.Set([method for method in dir(MapperExtension) - if not method.startswith('_')]) + interface = util.Set(method for method in dir(MapperExtension) + if not method.startswith('_')) def __init__(self, extensions=None): self.methods = {} diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index fff93df72..ac5c79009 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -282,8 +282,10 @@ class Table(SchemaItem, expression.TableClause): def __extra_kwargs(self, **kwargs): # validate remaining kwargs that they all specify DB prefixes - if len([k for k in kwargs if not re.match(r'^(?:%s)_' % '|'.join(databases.__all__), k)]): - raise TypeError("Invalid argument(s) for Table: %s" % repr(kwargs.keys())) + if len([k for k in kwargs + if not re.match(r'^(?:%s)_' % '|'.join(databases.__all__), k)]): + raise TypeError( + "Invalid argument(s) for Table: %s" % repr(kwargs.keys())) self.kwargs.update(kwargs) def __post_init(self, *args, **kwargs): @@ -1251,7 +1253,7 @@ class PrimaryKeyConstraint(Constraint): if kwargs: raise exc.ArgumentError( 'Unknown PrimaryKeyConstraint argument(s): %s' % - ', '.join([repr(x) for x in kwargs.keys()])) + ', '.join(repr(x) for x in kwargs.keys())) super(PrimaryKeyConstraint, self).__init__(**constraint_args) self.__colnames = list(columns) @@ -1314,7 +1316,7 @@ class UniqueConstraint(Constraint): if kwargs: raise exc.ArgumentError( 'Unknown UniqueConstraint argument(s): %s' % - ', '.join([repr(x) for x in kwargs.keys()])) + ', '.join(repr(x) for x in kwargs.keys())) super(UniqueConstraint, self).__init__(**constraint_args) self.__colnames = list(columns) @@ -1410,8 +1412,7 @@ class Index(SchemaItem): def __repr__(self): return 'Index("%s", %s%s)' % (self.name, - ', '.join([repr(c) - for c in self.columns]), + ', '.join(repr(c) for c in self.columns), (self.unique and ', unique=True') or '') class MetaData(SchemaItem): diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index df5e853fa..f21badf21 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -312,7 +312,8 @@ class DefaultCompiler(engine.Compiled): sep = ', ' else: sep = " " + self.operator_string(clauselist.operator) + " " - return sep.join([s for s in [self.process(c) for c in clauselist.clauses] if s is not None]) + return sep.join(s for s in (self.process(c) for c in clauselist.clauses) + if s is not None) def visit_calculatedclause(self, clause, **kwargs): return self.process(clause.clause_expr) @@ -346,7 +347,9 @@ class DefaultCompiler(engine.Compiled): stack_entry['is_subquery'] = True self.stack.append(stack_entry) - text = string.join([self.process(c, asfrom=asfrom, parens=False) for c in cs.selects], " " + cs.keyword + " ") + text = string.join((self.process(c, asfrom=asfrom, parens=False) + for c in cs.selects), + " " + cs.keyword + " ") group_by = self.process(cs._group_by_clause, asfrom=asfrom) if group_by: text += " GROUP BY " + group_by @@ -519,7 +522,7 @@ class DefaultCompiler(engine.Compiled): if froms: text += " \nFROM " - text += string.join(from_strings, ', ') + text += ', '.join(from_strings) else: text += self.default_from() @@ -602,9 +605,9 @@ class DefaultCompiler(engine.Compiled): return (insert + " INTO %s (%s) VALUES (%s)" % (preparer.format_table(insert_stmt.table), - ', '.join([preparer.quote(c[0].name, c[0].quote) - for c in colparams]), - ', '.join([c[1] for c in colparams]))) + ', '.join(preparer.quote(c[0].name, c[0].quote) + for c in colparams), + ', '.join(c[1] for c in colparams))) def visit_update(self, update_stmt): self.stack.append({'from':util.Set([update_stmt.table])}) @@ -612,7 +615,13 @@ class DefaultCompiler(engine.Compiled): self.isupdate = True colparams = self._get_colparams(update_stmt) - text = "UPDATE " + self.preparer.format_table(update_stmt.table) + " SET " + string.join(["%s=%s" % (self.preparer.quote(c[0].name, c[0].quote), c[1]) for c in colparams], ', ') + text = ' '.join(( + "UPDATE", + self.preparer.format_table(update_stmt.table), + 'SET', + ', '.join(self.preparer.quote(c[0].name, c[0].quote) + '=' + c[1] + for c in colparams) + )) if update_stmt._whereclause: text += " WHERE " + self.process(update_stmt._whereclause) @@ -645,7 +654,8 @@ class DefaultCompiler(engine.Compiled): if self.column_keys is None: parameters = {} else: - parameters = dict([(getattr(key, 'key', key), None) for key in self.column_keys]) + parameters = dict((getattr(key, 'key', key), None) + for key in self.column_keys) if stmt.parameters is not None: for k, v in stmt.parameters.iteritems(): @@ -789,8 +799,11 @@ class SchemaGenerator(DDLBase): if column.default is not None: self.traverse_single(column.default) - self.append("\n" + " ".join(['CREATE'] + table._prefixes + ['TABLE', self.preparer.format_table(table), "("])) - + self.append("\n" + " ".join(['CREATE'] + + table._prefixes + + ['TABLE', + self.preparer.format_table(table), + "("])) separator = "\n" # if only one primary key, specify it along with the column @@ -858,7 +871,8 @@ class SchemaGenerator(DDLBase): if constraint.name is not None: self.append("CONSTRAINT %s " % self.preparer.format_constraint(constraint)) self.append("PRIMARY KEY ") - self.append("(%s)" % ', '.join([self.preparer.quote(c.name, c.quote) for c in constraint])) + self.append("(%s)" % ', '.join(self.preparer.quote(c.name, c.quote) + for c in constraint)) self.define_constraint_deferrability(constraint) def visit_foreign_key_constraint(self, constraint): @@ -879,9 +893,11 @@ class SchemaGenerator(DDLBase): preparer.format_constraint(constraint)) table = list(constraint.elements)[0].column.table self.append("FOREIGN KEY(%s) REFERENCES %s (%s)" % ( - ', '.join([preparer.quote(f.parent.name, f.parent.quote) for f in constraint.elements]), + ', '.join(preparer.quote(f.parent.name, f.parent.quote) + for f in constraint.elements), preparer.format_table(table), - ', '.join([preparer.quote(f.column.name, f.column.quote) for f in constraint.elements]) + ', '.join(preparer.quote(f.column.name, f.column.quote) + for f in constraint.elements) )) if constraint.ondelete is not None: self.append(" ON DELETE %s" % constraint.ondelete) @@ -894,7 +910,7 @@ class SchemaGenerator(DDLBase): if constraint.name is not None: self.append("CONSTRAINT %s " % self.preparer.format_constraint(constraint)) - self.append(" UNIQUE (%s)" % (', '.join([self.preparer.quote(c.name, c.quote) for c in constraint]))) + self.append(" UNIQUE (%s)" % (', '.join(self.preparer.quote(c.name, c.quote) for c in constraint))) self.define_constraint_deferrability(constraint) def define_constraint_deferrability(self, constraint): @@ -917,7 +933,8 @@ class SchemaGenerator(DDLBase): self.append("INDEX %s ON %s (%s)" \ % (preparer.quote(self._validate_identifier(index.name, True), index.quote), preparer.format_table(index.table), - string.join([preparer.quote(c.name, c.quote) for c in index.columns], ', '))) + ', '.join(preparer.quote(c.name, c.quote) + for c in index.columns))) self.execute() diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 308f4b202..223739101 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -1501,7 +1501,8 @@ class ColumnElement(ClauseElement, _CompareMixin): def base_columns(self): if not hasattr(self, '_base_columns'): - self._base_columns = util.Set([c for c in self.proxy_set if not hasattr(c, 'proxies')]) + self._base_columns = util.Set(c for c in self.proxy_set + if not hasattr(c, 'proxies')) return self._base_columns base_columns = property(base_columns) @@ -1964,7 +1965,8 @@ class _TextClause(ClauseElement): type = property(type) def _copy_internals(self, clone=_clone): - self.bindparams = dict([(b.key, clone(b)) for b in self.bindparams.values()]) + self.bindparams = dict((b.key, clone(b)) + for b in self.bindparams.values()) def get_children(self, **kwargs): return self.bindparams.values() @@ -2317,8 +2319,9 @@ class Join(FromClause): global sql_util if not sql_util: from sqlalchemy.sql import util as sql_util - self._primary_key.extend(sql_util.reduce_columns([c for c in columns if c.primary_key], self.onclause)) - self._columns.update([(col._label, col) for col in columns]) + self._primary_key.extend(sql_util.reduce_columns( + (c for c in columns if c.primary_key), self.onclause)) + self._columns.update((col._label, col) for col in columns) self._foreign_keys.update(itertools.chain(*[col.foreign_keys for col in columns])) self._oid_column = self.left.oid_column @@ -2981,10 +2984,9 @@ class Select(_SelectBaseMixin, FromClause): self._whereclause = None if from_obj: - self._froms.update([ + self._froms.update( _is_literal(f) and _TextClause(f) or f - for f in util.to_list(from_obj) - ]) + for f in util.to_list(from_obj)) if having: self._having = _literal_as_text(having) @@ -3067,9 +3069,10 @@ class Select(_SelectBaseMixin, FromClause): def _copy_internals(self, clone=_clone): self._reset_exported() - from_cloned = dict([(f, clone(f)) for f in self._froms.union(self._correlate)]) - self._froms = util.Set([from_cloned[f] for f in self._froms]) - self._correlate = util.Set([from_cloned[f] for f in self._correlate]) + from_cloned = dict((f, clone(f)) + for f in self._froms.union(self._correlate)) + self._froms = util.Set(from_cloned[f] for f in self._froms) + self._correlate = util.Set(from_cloned[f] for f in self._correlate) self._raw_columns = [clone(c) for c in self._raw_columns] for attr in ('_whereclause', '_having', '_order_by_clause', '_group_by_clause'): if getattr(self, attr) is not None: diff --git a/lib/sqlalchemy/topological.py b/lib/sqlalchemy/topological.py index 9ef3dfaf4..c4c610b35 100644 --- a/lib/sqlalchemy/topological.py +++ b/lib/sqlalchemy/topological.py @@ -76,7 +76,7 @@ class _Node(object): str(self.item) + \ (self.cycles is not None and (" (cycles: " + repr([x for x in self.cycles]) + ")") or "") + \ "\n" + \ - ''.join([str(n) for n in self.children]) + ''.join(str(n) for n in self.children) def __repr__(self): return "%s" % (str(self.item)) @@ -150,7 +150,7 @@ class _EdgeCollection(object): yield child def __len__(self): - return sum([len(x) for x in self.parent_to_children.values()]) + return sum(len(x) for x in self.parent_to_children.values()) def __iter__(self): for parent, children in self.parent_to_children.iteritems(): @@ -301,7 +301,7 @@ def _find_cycles(edges): traverse(parent) # sets are not hashable, so uniquify with id - unique_cycles = dict([(id(s), s) for s in cycles.values()]).values() + unique_cycles = dict((id(s), s) for s in cycles.values()).values() for cycle in unique_cycles: edgecollection = [edge for edge in edges if edge[0] in cycle and edge[1] in cycle] diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index 6b6337754..163a6d7c4 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -152,8 +152,8 @@ class AbstractType(object): def __repr__(self): return "%s(%s)" % ( self.__class__.__name__, - ", ".join(["%s=%r" % (k, getattr(self, k, None)) - for k in inspect.getargspec(self.__init__)[0][1:]])) + ", ".join("%s=%r" % (k, getattr(self, k, None)) + for k in inspect.getargspec(self.__init__)[0][1:])) class TypeEngine(AbstractType): def dialect_impl(self, dialect, **kwargs): diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index c9982a9fa..7a6b964aa 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -525,7 +525,7 @@ def dictlike_iteritems(dictlike): yield key, getter(key) return iterator() elif hasattr(dictlike, 'keys'): - return iter([(key, getter(key)) for key in dictlike.keys()]) + return iter((key, getter(key)) for key in dictlike.keys()) else: raise TypeError( "Object '%r' is not dict-like" % dictlike) @@ -535,7 +535,7 @@ def assert_arg_type(arg, argtype, name): return arg else: if isinstance(argtype, tuple): - raise exc.ArgumentError("Argument '%s' is expected to be one of type %s, got '%s'" % (name, ' or '.join(["'%s'" % str(a) for a in argtype]), str(type(arg)))) + raise exc.ArgumentError("Argument '%s' is expected to be one of type %s, got '%s'" % (name, ' or '.join("'%s'" % str(a) for a in argtype), str(type(arg)))) else: raise exc.ArgumentError("Argument '%s' is expected to be of type '%s', got '%s'" % (name, str(argtype), str(type(arg)))) @@ -856,21 +856,21 @@ class OrderedSet(Set): def intersection(self, other): other = Set(other) - return self.__class__([a for a in self if a in other]) + return self.__class__(a for a in self if a in other) __and__ = intersection def symmetric_difference(self, other): other = Set(other) - result = self.__class__([a for a in self if a not in other]) - result.update([a for a in other if a not in self]) + result = self.__class__(a for a in self if a not in other) + result.update(a for a in other if a not in self) return result __xor__ = symmetric_difference def difference(self, other): other = Set(other) - return self.__class__([a for a in self if a not in other]) + return self.__class__(a for a in self if a not in other) __sub__ = difference @@ -1233,7 +1233,7 @@ class WeakCompositeKey(object): return cmp(tuple(self), tuple(other)) def __iter__(self): - return iter([arg() for arg in self.args]) + return iter(arg() for arg in self.args) class _symbol(object): def __init__(self, name): @@ -1,10 +1,14 @@ from ez_setup import use_setuptools use_setuptools() +import os +import sys +from os import path from setuptools import setup, find_packages from distutils.command.build_py import build_py as _build_py from setuptools.command.sdist import sdist as _sdist -import os -from os import path + +if sys.version_info < (2, 4): + raise Exception("SQLAlchemy requires Python 2.4 or higher.") v = open(path.join(path.dirname(__file__), 'VERSION')) VERSION = v.readline().strip() diff --git a/test/profiling/compiler.py b/test/profiling/compiler.py index a62c63c6b..b37b63297 100644 --- a/test/profiling/compiler.py +++ b/test/profiling/compiler.py @@ -15,7 +15,7 @@ class CompileTest(TestBase, AssertsExecutionResults): Column('c1', Integer, primary_key=True), Column('c2', String(30))) - @profiling.function_call_count(67, {'2.3': 44, '2.4': 42}) + @profiling.function_call_count(72, {'2.3': 44, '2.4': 46}) def test_insert(self): t1.insert().compile() |