From 4b614b9b35cd2baddb7ca67c04bee5d70ec6a172 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 27 Apr 2013 19:53:57 -0400 Subject: - the raw 2to3 run - went through examples/ and cleaned out excess list() calls --- lib/sqlalchemy/orm/query.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'lib/sqlalchemy/orm/query.py') diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index c9f3a2699..80441b976 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -47,7 +47,7 @@ def _generative(*assertions): def generate(fn, *args, **kw): self = args[0]._clone() for assertion in assertions: - assertion(self, fn.func_name) + assertion(self, fn.__name__) fn(self, *args[1:], **kw) return self return generate @@ -981,11 +981,12 @@ class Query(object): """Return a scalar result corresponding to the given column expression.""" try: - # Py3K - #return self.values(column).__next__()[0] - # Py2K - return self.values(column).next()[0] - # end Py2K +# start Py3K + return self.values(column).__next__()[0] +# end Py3K +# start Py2K +# return self.values(column).next()[0] +# end Py2K except StopIteration: return None @@ -1231,7 +1232,7 @@ class Query(object): """ clauses = [_entity_descriptor(self._joinpoint_zero(), key) == value - for key, value in kwargs.iteritems()] + for key, value in kwargs.items()] return self.filter(sql.and_(*clauses)) @_generative(_no_statement_condition, _no_limit_offset) @@ -1296,7 +1297,7 @@ class Query(object): """ - if isinstance(criterion, basestring): + if isinstance(criterion, str): criterion = sql.text(criterion) if criterion is not None and \ @@ -1655,7 +1656,7 @@ class Query(object): kwargs.pop('from_joinpoint', False) if kwargs: raise TypeError("unknown arguments: %s" % - ','.join(kwargs.iterkeys())) + ','.join(iter(kwargs.keys()))) return self._join(props, outerjoin=False, create_aliases=aliased, from_joinpoint=from_joinpoint) @@ -1671,7 +1672,7 @@ class Query(object): kwargs.pop('from_joinpoint', False) if kwargs: raise TypeError("unknown arguments: %s" % - ','.join(kwargs.iterkeys())) + ','.join(iter(kwargs.keys()))) return self._join(props, outerjoin=True, create_aliases=aliased, from_joinpoint=from_joinpoint) @@ -1701,7 +1702,7 @@ class Query(object): if len(keys) == 2 and \ isinstance(keys[0], (expression.FromClause, type, AliasedClass)) and \ - isinstance(keys[1], (basestring, expression.ClauseElement, + isinstance(keys[1], (str, expression.ClauseElement, interfaces.PropComparator)): # detect 2-arg form of join and # convert to a tuple. @@ -1721,14 +1722,14 @@ class Query(object): # is a little bit of legacy behavior still at work here # which means they might be in either order. may possibly # lock this down to (right_entity, onclause) in 0.6. - if isinstance(arg1, (interfaces.PropComparator, basestring)): + if isinstance(arg1, (interfaces.PropComparator, str)): right_entity, onclause = arg2, arg1 else: right_entity, onclause = arg1, arg2 left_entity = prop = None - if isinstance(onclause, basestring): + if isinstance(onclause, str): left_entity = self._joinpoint_zero() descriptor = _entity_descriptor(left_entity, onclause) @@ -1922,7 +1923,7 @@ class Query(object): clause = orm_join(clause, right, onclause, isouter=outerjoin) - except sa_exc.ArgumentError, ae: + except sa_exc.ArgumentError as ae: raise sa_exc.InvalidRequestError( "Could not find a FROM clause to join from. " "Tried joining to %s, but got: %s" % (right, ae)) @@ -1947,7 +1948,7 @@ class Query(object): try: clause = orm_join(clause, right, onclause, isouter=outerjoin) - except sa_exc.ArgumentError, ae: + except sa_exc.ArgumentError as ae: raise sa_exc.InvalidRequestError( "Could not find a FROM clause to join from. " "Tried joining to %s, but got: %s" % (right, ae)) @@ -2115,7 +2116,7 @@ class Query(object): appropriate to the entity class represented by this ``Query``. """ - if isinstance(statement, basestring): + if isinstance(statement, str): statement = sql.text(statement) if not isinstance(statement, @@ -2609,7 +2610,7 @@ class Query(object): use_labels=context.labels) from_clause = inner - for eager_join in context.eager_joins.values(): + for eager_join in list(context.eager_joins.values()): # EagerLoader places a 'stop_on' attribute on the join, # giving us a marker as to where the "splice point" of # the join should be @@ -2674,7 +2675,7 @@ class Query(object): subtypes are selected from the total results. """ - for (ext_info, adapter) in self._mapper_adapter_map.values(): + for (ext_info, adapter) in list(self._mapper_adapter_map.values()): if ext_info in self._join_entities: continue single_crit = ext_info.mapper._single_table_criterion @@ -2697,7 +2698,7 @@ class _QueryEntity(object): def __new__(cls, *args, **kwargs): if cls is _QueryEntity: entity = args[1] - if not isinstance(entity, basestring) and \ + if not isinstance(entity, str) and \ _is_mapped_class(entity): cls = _MapperEntity else: @@ -2905,7 +2906,7 @@ class _ColumnEntity(_QueryEntity): self.expr = column self.namespace = namespace - if isinstance(column, basestring): + if isinstance(column, str): column = sql.literal_column(column) self._label_name = column.name elif isinstance(column, ( @@ -3080,7 +3081,7 @@ class AliasOption(interfaces.MapperOption): self.alias = alias def process_query(self, query): - if isinstance(self.alias, basestring): + if isinstance(self.alias, str): alias = query._mapper_zero().mapped_table.alias(self.alias) else: alias = self.alias -- cgit v1.2.1 From 220fa91337aced11789b23065289203414f2063d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 May 2013 16:23:27 -0400 Subject: most of ORM passing... --- lib/sqlalchemy/orm/query.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'lib/sqlalchemy/orm/query.py') diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 80441b976..09f0bedd1 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -981,12 +981,7 @@ class Query(object): """Return a scalar result corresponding to the given column expression.""" try: -# start Py3K - return self.values(column).__next__()[0] -# end Py3K -# start Py2K -# return self.values(column).next()[0] -# end Py2K + return next(self.values(column))[0] except StopIteration: return None -- cgit v1.2.1 From 3d75ff22d3e53b7f6b5965d680157b9453fc8154 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 13:09:38 -0400 Subject: repair py3kisms in key ORM modules --- lib/sqlalchemy/orm/query.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lib/sqlalchemy/orm/query.py') diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 09f0bedd1..cb788e0a4 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -1292,7 +1292,7 @@ class Query(object): """ - if isinstance(criterion, str): + if isinstance(criterion, util.string_types): criterion = sql.text(criterion) if criterion is not None and \ @@ -1651,7 +1651,7 @@ class Query(object): kwargs.pop('from_joinpoint', False) if kwargs: raise TypeError("unknown arguments: %s" % - ','.join(iter(kwargs.keys()))) + ','.join(kwargs.keys)) return self._join(props, outerjoin=False, create_aliases=aliased, from_joinpoint=from_joinpoint) @@ -1667,7 +1667,7 @@ class Query(object): kwargs.pop('from_joinpoint', False) if kwargs: raise TypeError("unknown arguments: %s" % - ','.join(iter(kwargs.keys()))) + ','.join(kwargs)) return self._join(props, outerjoin=True, create_aliases=aliased, from_joinpoint=from_joinpoint) @@ -1717,14 +1717,14 @@ class Query(object): # is a little bit of legacy behavior still at work here # which means they might be in either order. may possibly # lock this down to (right_entity, onclause) in 0.6. - if isinstance(arg1, (interfaces.PropComparator, str)): + if isinstance(arg1, (interfaces.PropComparator, util.string_types)): right_entity, onclause = arg2, arg1 else: right_entity, onclause = arg1, arg2 left_entity = prop = None - if isinstance(onclause, str): + if isinstance(onclause, util.string_types): left_entity = self._joinpoint_zero() descriptor = _entity_descriptor(left_entity, onclause) @@ -2111,7 +2111,7 @@ class Query(object): appropriate to the entity class represented by this ``Query``. """ - if isinstance(statement, str): + if isinstance(statement, util.string_types): statement = sql.text(statement) if not isinstance(statement, @@ -2605,7 +2605,7 @@ class Query(object): use_labels=context.labels) from_clause = inner - for eager_join in list(context.eager_joins.values()): + for eager_join in context.eager_joins.values(): # EagerLoader places a 'stop_on' attribute on the join, # giving us a marker as to where the "splice point" of # the join should be @@ -2670,7 +2670,7 @@ class Query(object): subtypes are selected from the total results. """ - for (ext_info, adapter) in list(self._mapper_adapter_map.values()): + for (ext_info, adapter) in self._mapper_adapter_map.values(): if ext_info in self._join_entities: continue single_crit = ext_info.mapper._single_table_criterion @@ -2693,7 +2693,7 @@ class _QueryEntity(object): def __new__(cls, *args, **kwargs): if cls is _QueryEntity: entity = args[1] - if not isinstance(entity, str) and \ + if not isinstance(entity, util.string_types) and \ _is_mapped_class(entity): cls = _MapperEntity else: @@ -2901,7 +2901,7 @@ class _ColumnEntity(_QueryEntity): self.expr = column self.namespace = namespace - if isinstance(column, str): + if isinstance(column, util.string_types): column = sql.literal_column(column) self._label_name = column.name elif isinstance(column, ( @@ -3076,7 +3076,7 @@ class AliasOption(interfaces.MapperOption): self.alias = alias def process_query(self, query): - if isinstance(self.alias, str): + if isinstance(self.alias, util.string_types): alias = query._mapper_zero().mapped_table.alias(self.alias) else: alias = self.alias -- cgit v1.2.1