Skip to content

Commit

Permalink
Get rid of all comprehensions and yielding in _multidict #410
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Jun 13, 2015
1 parent bb7c926 commit 6d72158
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions aiohttp/_multidict.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from collections import abc
from collections.abc import Iterable, Set
from operators import itemgetter


_marker = object()
Expand Down Expand Up @@ -359,7 +360,6 @@ abc.MutableMapping.register(CIMultiDict)

cdef class _ViewBase:

cdef list _keys
cdef list _items

def __cinit__(self, list items):
Expand Down Expand Up @@ -408,17 +408,21 @@ cdef class _ViewBaseSet(_ViewBase):
def __and__(self, other):
if not isinstance(other, Iterable):
return NotImplemented
return set(self) & set(other)
if not isinstance(other, Set):
other = set(other)
return set(self) & other

def __or__(self, other):
if not isinstance(other, Iterable):
return NotImplemented
return set(self) | set(other)
if not isinstance(other, Set):
other = set(other)
return set(self) | other

def __sub__(self, other):
if not isinstance(other, Iterable):
return NotImplemented
if not isinstance(other, Set):
if not isinstance(other, Iterable):
return NotImplemented
other = set(other)
return set(self) - other

Expand Down Expand Up @@ -462,9 +466,7 @@ cdef class _ValuesView(_ViewBase):
return False

def __iter__(self):
cdef tuple item
for item in self._items:
yield item[1]
return map(itemgetter(1), self._items)


abc.ValuesView.register(_ValuesView)
Expand All @@ -488,9 +490,7 @@ cdef class _KeysView(_ViewBaseSet):
return False

def __iter__(self):
cdef tuple item
for item in self._items:
yield item[0]
return map(itemgetter(0), self._items)


abc.KeysView.register(_KeysView)
4 changes: 2 additions & 2 deletions tests/test_multidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ def test_sub_issue_410(self):
try:
raise Exception
except Exception as e:
d.keys() & {'other'}
d.keys() - {'other'}
self.assertIs(sys.exc_info()[1], e)

def test_xor_issue_410(self):
d = self.make_dict([('key', 'value')])
try:
raise Exception
except Exception as e:
d.keys() & {'other'}
d.keys() ^ {'other'}
self.assertIs(sys.exc_info()[1], e)


Expand Down

0 comments on commit 6d72158

Please sign in to comment.