mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-23 01:56:54 +03:00
Removed LazyMap
This commit is contained in:
parent
c521e181c8
commit
137ba49868
|
@ -1,11 +1,10 @@
|
||||||
from .str_converters import to_camel_case, to_snake_case
|
from .str_converters import to_camel_case, to_snake_case
|
||||||
from .proxy_snake_dict import ProxySnakeDict
|
from .proxy_snake_dict import ProxySnakeDict
|
||||||
from .caching import cached_property, memoize
|
from .caching import cached_property, memoize
|
||||||
from .lazymap import LazyMap
|
|
||||||
from .misc import enum_to_graphql_enum
|
from .misc import enum_to_graphql_enum
|
||||||
from .resolve_only_args import resolve_only_args
|
from .resolve_only_args import resolve_only_args
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['to_camel_case', 'to_snake_case', 'ProxySnakeDict',
|
__all__ = ['to_camel_case', 'to_snake_case', 'ProxySnakeDict',
|
||||||
'cached_property', 'memoize', 'LazyMap', 'enum_to_graphql_enum',
|
'cached_property', 'memoize', 'enum_to_graphql_enum',
|
||||||
'resolve_only_args']
|
'resolve_only_args']
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
class LazyMap(object):
|
|
||||||
|
|
||||||
def __init__(self, origin, _map, state=None):
|
|
||||||
self._origin = origin
|
|
||||||
self._origin_iter = origin.__iter__()
|
|
||||||
self._state = state or []
|
|
||||||
self._finished = False
|
|
||||||
self._map = _map
|
|
||||||
|
|
||||||
def __iter__(self):
|
|
||||||
return self if not self._finished else iter(self._state)
|
|
||||||
|
|
||||||
def iter(self):
|
|
||||||
return self.__iter__()
|
|
||||||
|
|
||||||
def __len__(self):
|
|
||||||
return self._origin.__len__()
|
|
||||||
|
|
||||||
def __next__(self):
|
|
||||||
try:
|
|
||||||
n = next(self._origin_iter)
|
|
||||||
n = self._map(n)
|
|
||||||
except StopIteration as e:
|
|
||||||
self._finished = True
|
|
||||||
raise e
|
|
||||||
else:
|
|
||||||
self._state.append(n)
|
|
||||||
return n
|
|
||||||
|
|
||||||
def next(self):
|
|
||||||
return self.__next__()
|
|
||||||
|
|
||||||
def __getitem__(self, key):
|
|
||||||
item = self._origin[key]
|
|
||||||
if isinstance(key, slice):
|
|
||||||
return LazyMap(item, self._map)
|
|
||||||
return self._map(item)
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
|
||||||
return getattr(self._origin, name)
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return "<LazyMap %s>" % repr(self._origin)
|
|
|
@ -1,23 +0,0 @@
|
||||||
from py.test import raises
|
|
||||||
|
|
||||||
from ..lazymap import LazyMap
|
|
||||||
|
|
||||||
|
|
||||||
def test_lazymap():
|
|
||||||
data = list(range(10))
|
|
||||||
lm = LazyMap(data, lambda x: 2 * x)
|
|
||||||
assert len(lm) == 10
|
|
||||||
assert lm[1] == 2
|
|
||||||
assert isinstance(lm[1:4], LazyMap)
|
|
||||||
assert lm.append == data.append
|
|
||||||
assert repr(lm) == '<LazyMap [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>'
|
|
||||||
|
|
||||||
|
|
||||||
def test_lazymap_iter():
|
|
||||||
data = list(range(2))
|
|
||||||
lm = LazyMap(data, lambda x: 2 * x)
|
|
||||||
iter_lm = iter(lm)
|
|
||||||
assert iter_lm.next() == 0
|
|
||||||
assert iter_lm.next() == 2
|
|
||||||
with raises(StopIteration):
|
|
||||||
iter_lm.next()
|
|
Loading…
Reference in New Issue
Block a user