.. changelog::
:version: 0.9.1
+ .. change::
+ :tags: feature, core
+
+ Conjunctions like :func:`.and_` and :func:`.or_` can now accept
+ Python generators as a single argument, e.g.::
+
+ and_(x == y for x, y in tuples)
+
+ The logic here looks for a single argument ``*args`` where the first
+ element is an instance of ``types.GeneratorType``.
+
.. change::
:tags: feature, core
def _construct(cls, operator, continue_on, skip_on, *clauses, **kw):
convert_clauses = []
+ clauses = util.coerce_generator_arg(clauses)
for clause in clauses:
clause = _literal_as_text(clause)
column_dict, ordered_column_set, populate_column_dict, unique_list, \
UniqueAppender, PopulateDict, EMPTY_SET, to_list, to_set, \
to_column_set, update_copy, flatten_iterator, \
- LRUCache, ScopedRegistry, ThreadLocalRegistry, WeakSequence
+ LRUCache, ScopedRegistry, ThreadLocalRegistry, WeakSequence, \
+ coerce_generator_arg
from .langhelpers import iterate_attributes, class_hierarchy, \
portable_instancemethod, unbound_method_to_callable, \
"""Collection classes and helpers."""
+from __future__ import absolute_import
import weakref
import operator
from .compat import threading, itertools_filterfalse
from . import py2k
+import types
EMPTY_SET = frozenset()
def __iter__(self):
return iter(self.data)
+def coerce_generator_arg(arg):
+ if len(arg) == 1 and isinstance(arg[0], types.GeneratorType):
+ return list(arg[0])
+ else:
+ return arg
def to_list(x, default=None):
if x is None:
'otherid_1': 9, 'myid_1': 12}
)
+ # test a generator
+ self.assert_compile(
+ and_(
+ conj for conj in [
+ table1.c.myid == 12,
+ table1.c.name == 'asdf'
+ ]
+ ),
+ "mytable.myid = :myid_1 AND mytable.name = :name_1"
+ )
+
def test_nested_conjunctions_short_circuit(self):
"""test that empty or_(), and_() conjunctions are collapsed by
an enclosing conjunction."""