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.
This commit is contained in:
Greg Ward
2019-10-30 10:33:00 -04:00
committed by Jelle Zijlstra
parent c8405bb5d9
commit 603458ba09

View File

@@ -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: