From 137ba498682a1b559f0e746da2a503f6add37eb4 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sat, 21 Nov 2015 10:58:49 -0800 Subject: [PATCH] Removed LazyMap --- graphene/utils/__init__.py | 3 +- graphene/utils/lazymap.py | 43 ---------------------------- graphene/utils/tests/test_lazymap.py | 23 --------------- 3 files changed, 1 insertion(+), 68 deletions(-) delete mode 100644 graphene/utils/lazymap.py delete mode 100644 graphene/utils/tests/test_lazymap.py diff --git a/graphene/utils/__init__.py b/graphene/utils/__init__.py index bb1a2150..52fb6417 100644 --- a/graphene/utils/__init__.py +++ b/graphene/utils/__init__.py @@ -1,11 +1,10 @@ from .str_converters import to_camel_case, to_snake_case from .proxy_snake_dict import ProxySnakeDict from .caching import cached_property, memoize -from .lazymap import LazyMap from .misc import enum_to_graphql_enum from .resolve_only_args import resolve_only_args __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'] diff --git a/graphene/utils/lazymap.py b/graphene/utils/lazymap.py deleted file mode 100644 index 236f91eb..00000000 --- a/graphene/utils/lazymap.py +++ /dev/null @@ -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 "" % repr(self._origin) diff --git a/graphene/utils/tests/test_lazymap.py b/graphene/utils/tests/test_lazymap.py deleted file mode 100644 index e6ee1f36..00000000 --- a/graphene/utils/tests/test_lazymap.py +++ /dev/null @@ -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) == '' - - -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()