From: Mike Bayer Date: Fri, 15 Aug 2014 18:57:29 +0000 (-0400) Subject: - TIL that dict.keys() in py3K is not an iterator, it is an iterable X-Git-Tag: rel_1_0_0b1~222 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5a68f856daee59caf4c9da7d06880eada9d70302;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - TIL that dict.keys() in py3K is not an iterator, it is an iterable view. So copy collections.OrderedDict and use MutableMapping to set up keys, items, values on our own OrderedDict. Conflicts: lib/sqlalchemy/engine/base.py --- diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 3728b59fd0..d2cc8890fd 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -798,8 +798,8 @@ class Connection(Connectable): distilled_params = _distill_params(multiparams, params) if distilled_params: # note this is usually dict but we support RowProxy - # as well; but dict.keys() as an iterator is OK - keys = list(distilled_params[0].keys()) + # as well; but dict.keys() as an iterable is OK + keys = distilled_params[0].keys() else: keys = [] diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index 5236d0120f..fa27897a11 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -13,6 +13,7 @@ import operator from .compat import threading, itertools_filterfalse from . import py2k import types +from collections import MutableMapping EMPTY_SET = frozenset() @@ -264,13 +265,11 @@ class OrderedDict(dict): def __iter__(self): return iter(self._list) - if py2k: - def values(self): - return [self[key] for key in self._list] - - def keys(self): - return self._list + keys = MutableMapping.keys + values = MutableMapping.values + items = MutableMapping.items + if py2k: def itervalues(self): return iter([self[key] for key in self._list]) @@ -280,41 +279,6 @@ class OrderedDict(dict): def iteritems(self): return iter(self.items()) - def items(self): - return [(key, self[key]) for key in self._list] - else: - def values(self): - # return (self[key] for key in self) - return (self[key] for key in self._list) - - def keys(self): - # return iter(self) - return iter(self._list) - - def items(self): - # return ((key, self[key]) for key in self) - return ((key, self[key]) for key in self._list) - - _debug_iter = False - if _debug_iter: - # normally disabled to reduce function call - # overhead - def __iter__(self): - len_ = len(self._list) - for item in self._list: - yield item - assert len_ == len(self._list), \ - "Dictionary changed size during iteration" - - def values(self): - return (self[key] for key in self) - - def keys(self): - return iter(self) - - def items(self): - return ((key, self[key]) for key in self) - def __setitem__(self, key, object): if key not in self: try: