From 603458ba0957174cdac7e7a78abfc82bba015070 Mon Sep 17 00:00:00 2001 From: Greg Ward Date: Wed, 30 Oct 2019 10:33:00 -0400 Subject: [PATCH] Fix some incorrect/incomplete annotations for redis.client.PubSub (#3408) * redis: Fix return value declarations in redis.client.PubSub get_message() was declared incorrectly. Start here: https://github.com/andymccurdy/redis-py/blob/3.3.11/redis/client.py#L3298-L3300 where it's obvious that get_message() returns either None or the output of handle_message(). So what does handle_message() return? Combine: https://github.com/andymccurdy/redis-py/blob/3.3.11/redis/client.py#L3316-L3336 https://github.com/andymccurdy/redis-py/blob/3.3.11/redis/client.py#L3366 and you can see it returns None or a dict mapping str to something. * redis: Fix incorrect declaration for PubSub.get_message() argument Docstrings says it's a float: https://github.com/andymccurdy/redis-py/blob/3.3.11/redis/client.py#L3293-L3295 And it eventually gets passed to settimeout() on a socket: https://github.com/andymccurdy/redis-py/blob/3.3.11/redis/connection.py#L182 * redis: Annotate one more method arg in PubSub class get_message() and handle_message() are closely related: ignore_subscribe_message does the same in both, and its default value in both is False. --- third_party/2and3/redis/client.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/third_party/2and3/redis/client.pyi b/third_party/2and3/redis/client.pyi index ea692bb1a..0dec09a0e 100644 --- a/third_party/2and3/redis/client.pyi +++ b/third_party/2and3/redis/client.pyi @@ -1,5 +1,5 @@ from datetime import timedelta -from typing import Any, Iterable, Text, Optional, Mapping, Tuple, Union, Callable, List +from typing import Any, Iterable, Text, Optional, Mapping, Tuple, Union, Callable, List, Dict from .connection import ConnectionPool @@ -307,8 +307,8 @@ class PubSub: def subscribe(self, *args: Text, **kwargs: Callable[[Any], None]) -> None: ... def unsubscribe(self, *args: Text) -> None: ... def listen(self): ... - def get_message(self, ignore_subscribe_messages: bool = ..., timeout: int = ...) -> Optional[bytes]: ... - def handle_message(self, response, ignore_subscribe_messages=...): ... + def get_message(self, ignore_subscribe_messages: bool = ..., timeout: float = ...) -> Optional[Dict[str, Any]]: ... + def handle_message(self, response, ignore_subscribe_messages: bool = ...) -> Optional[Dict[str, Any]]: ... def run_in_thread(self, sleep_time=...): ... class BasePipeline: