-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[redis] pipeline return types (again) #6028
Comments
Detecting this at type check time doesn't seem to be possible, as it depends on This would be yet another good use case for AnyOf (python/typing#566 ), but that doesn't exist yet. One workaround would be to define the return type as pipe = pipe.set('foo', 'bar').incr('baz').decrrr('bang') # error: no method 'decrrr' But you can also do this: foo = pipe_that_does_not_return_pipes.some_method()
assert not isinstance(foo, Pipeline)
# now foo has type Any |
While manual setting of the watches isn't easy to track, in theory it is possible to handle the cases where the Its signatures are something like this: def transaction(self, func: Callable[[LazyPipeline], Any], **kwargs: Any): ...
def transaction(self, func: Callable[[ImmediatePipeline], Any], *watches, **kwargs: Any): ... However I'm not sure how overload detection will work given that we want it to only pick the latter when ( |
Including working around python/typeshed#6028.
Including working around python/typeshed#6028.
One more thing: in For example: current_rate, _ = await pipeline.incr(cache_key).expire( # type: ignore
cache_key,
self._rate_spec.seconds,
nx=True,
).execute() I have to use In real life it works just fine: https://github.com/wemake-services/asyncio-redis-rate-limit/blob/a47c75d01bdd9d8b95cdc65c95bf0677261d863e/asyncio_redis_rate_limit/__init__.py#L104-L109 |
This was fixed in #8325. |
In #4989 the return types of the pipeline methods were changed so that they would all return pipeline instances, but that's not always correct. If the pipeline is watching keys and isn't in the explicit transaction (after the MULTI) then it actually executes the command and returns the result.
@chdsbd @srittau
The text was updated successfully, but these errors were encountered: