]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
repair py3kisms in key ORM modules
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 26 May 2013 17:09:38 +0000 (13:09 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 26 May 2013 17:09:38 +0000 (13:09 -0400)
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/orm/util.py

index 645bf86e7020af42d46c6e353689a899484d2a7a..285d338dea48aa438b91db237fef24187ab8247b 100644 (file)
@@ -582,7 +582,7 @@ class Mapper(_InspectionAttr):
         if with_polymorphic == '*':
             self.with_polymorphic = ('*', None)
         elif isinstance(with_polymorphic, (tuple, list)):
-            if isinstance(with_polymorphic[0], (str, tuple, list)):
+            if isinstance(with_polymorphic[0], util.string_types + (tuple, list)):
                 self.with_polymorphic = with_polymorphic
             else:
                 self.with_polymorphic = (with_polymorphic, None)
@@ -920,7 +920,7 @@ class Mapper(_InspectionAttr):
         if self.polymorphic_on is not None:
             setter = True
 
-            if isinstance(self.polymorphic_on, str):
+            if isinstance(self.polymorphic_on, util.string_types):
                 # polymorphic_on specified as as string - link
                 # it to mapped ColumnProperty
                 try:
@@ -1973,7 +1973,7 @@ class Mapper(_InspectionAttr):
         visited_states = set()
         prp, mpp = object(), object()
 
-        visitables = deque([(deque(list(self._props.values())), prp,
+        visitables = deque([(deque(self._props.values()), prp,
                                 state, state.dict)])
 
         while visitables:
@@ -1995,7 +1995,7 @@ class Mapper(_InspectionAttr):
                                 corresponding_dict = iterator.popleft()
                 yield instance, instance_mapper, \
                         corresponding_state, corresponding_dict
-                visitables.append((deque(list(instance_mapper._props.values())),
+                visitables.append((deque(instance_mapper._props.values()),
                                         prp, corresponding_state,
                                         corresponding_dict))
 
@@ -2012,7 +2012,7 @@ class Mapper(_InspectionAttr):
                 table_to_mapper.setdefault(t, mapper)
 
         extra_dependencies = []
-        for table, mapper in list(table_to_mapper.items()):
+        for table, mapper in table_to_mapper.items():
             super_ = mapper.inherits
             if super_:
                 extra_dependencies.extend([
@@ -2041,7 +2041,7 @@ class Mapper(_InspectionAttr):
                     return fk.parent not in cols
             return False
 
-        sorted_ = sql_util.sort_tables(iter(table_to_mapper.keys()),
+        sorted_ = sql_util.sort_tables(table_to_mapper,
                                     skip_fn=skip,
                                     extra_dependencies=extra_dependencies)
 
index 09f0bedd1386eaa6deb3514f86e3ae047cf89627..cb788e0a43f4877f05fd417a9e24e7a2e7de763b 100644 (file)
@@ -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
index 8a26bd8347dcfe10bdd9bce25a65ccc0ff705d8d..ddc0dd81822e9d4c9a7fdabe7b91eb29ca867524 100644 (file)
@@ -120,7 +120,7 @@ def polymorphic_union(table_map, typecolname,
     colnames = util.OrderedSet()
     colnamemaps = {}
     types = {}
-    for key in list(table_map.keys()):
+    for key in table_map:
         table = table_map[key]
 
         # mysql doesnt like selecting from a select;
@@ -203,7 +203,7 @@ def identity_key(*args, **kwargs):
                 "positional arguments, got %s" % len(args))
         if kwargs:
             raise sa_exc.ArgumentError("unknown keyword arguments: %s"
-                % ", ".join(list(kwargs.keys())))
+                % ", ".join(kwargs))
         mapper = class_mapper(class_)
         if "ident" in locals():
             return mapper.identity_key_from_primary_key(util.to_list(ident))
@@ -211,7 +211,7 @@ def identity_key(*args, **kwargs):
     instance = kwargs.pop("instance")
     if kwargs:
         raise sa_exc.ArgumentError("unknown keyword arguments: %s"
-            % ", ".join(list(kwargs.keys())))
+            % ", ".join(kwargs.keys))
     mapper = object_mapper(instance)
     return mapper.identity_key_from_instance(instance)
 
@@ -888,7 +888,7 @@ class _ORMJoin(expression.Join):
 
         self._joined_from_info = right_info
 
-        if isinstance(onclause, str):
+        if isinstance(onclause, util.string_types):
             onclause = getattr(left_orm_info.entity, onclause)
 
         if isinstance(onclause, attributes.QueryableAttribute):
@@ -1009,7 +1009,7 @@ def with_parent(instance, prop):
       parent/child relationship.
 
     """
-    if isinstance(prop, str):
+    if isinstance(prop, util.string_types):
         mapper = object_mapper(instance)
         prop = getattr(mapper.class_, prop).property
     elif isinstance(prop, attributes.QueryableAttribute):