@@ -48,14 +48,18 @@ def decorate(cls):
48
48
)
49
49
elif attr == "get_many" :
50
50
setattr (cls , attr , decorator (attribute , return_value = {}))
51
+ elif attr in {"iter_keys" , "sscan_iter" }:
52
+ setattr (cls , attr , decorator (attribute , gen = True ))
51
53
else :
52
54
setattr (cls , attr , decorator (attribute ))
53
55
return cls
54
56
55
57
return decorate
56
58
57
59
58
- def omit_exception (method : Callable | None = None , return_value : Any | None = None ):
60
+ def omit_exception (
61
+ method : Callable | None = None , return_value : Any | None = None , gen : bool = False
62
+ ):
59
63
"""
60
64
Simple decorator that intercepts connection
61
65
errors and ignores these if settings specify this.
@@ -102,10 +106,10 @@ async def _async_generator_decorator(self, *args, **kwargs):
102
106
except ConnectionInterrupted as e :
103
107
yield __handle_error (self , e )
104
108
105
- # inspect.isfunction returns true for generators, so can't use that to check this
106
- if not inspect . isasyncgenfunction ( method ) and not inspect . isgeneratorfunction (
107
- method
108
- ) :
109
+ # sync generators (iter_keys, sscan_iter) are only generator on client class
110
+ # in the backend they are just a function (that returns a generator)
111
+ # so inspect.isgeneratorfunction does not work
112
+ if not inspect . isasyncgenfunction ( method ) and not gen :
109
113
wrapper = _async_decorator if iscoroutinefunction (method ) else _decorator
110
114
111
115
# if method is a generator or async generator, it should be iterated over by this decorator
0 commit comments