diff options
| author | Chayim I. Kirshen <c@kirshen.com> | 2022-11-29 13:08:51 +0200 |
|---|---|---|
| committer | Chayim I. Kirshen <c@kirshen.com> | 2022-11-29 13:08:51 +0200 |
| commit | 87bae8e0f298b684a47eb66a655d3d8f38959c6f (patch) | |
| tree | ecee0a6bc1f936a69424968365544e3ae79fc72c | |
| parent | 199634ea195a45cd511fd709f887eebc68cfb9d2 (diff) | |
| download | redis-py-87bae8e0f298b684a47eb66a655d3d8f38959c6f.tar.gz | |
Signifying that parsers should be private
| -rw-r--r-- | redis/asyncio/connection.py | 6 | ||||
| -rwxr-xr-x | redis/connection.py | 6 | ||||
| -rw-r--r-- | redis/parsers/__init__.py | 8 | ||||
| -rw-r--r-- | redis/parsers/base.py (renamed from redis/parsers/protocol.py) | 0 | ||||
| -rw-r--r-- | redis/parsers/hiredis.py | 5 | ||||
| -rw-r--r-- | redis/parsers/resp2.py | 6 | ||||
| -rw-r--r-- | tests/test_asyncio/conftest.py | 6 | ||||
| -rw-r--r-- | tests/test_asyncio/test_connection.py | 6 | ||||
| -rw-r--r-- | tests/test_asyncio/test_encoding.py | 1 | ||||
| -rw-r--r-- | tests/test_asyncio/test_pubsub.py | 2 | ||||
| -rw-r--r-- | tests/test_encoding.py | 1 | ||||
| -rw-r--r-- | tests/test_pubsub.py | 2 |
12 files changed, 24 insertions, 25 deletions
diff --git a/redis/asyncio/connection.py b/redis/asyncio/connection.py index 4faee34..f912970 100644 --- a/redis/asyncio/connection.py +++ b/redis/asyncio/connection.py @@ -43,7 +43,7 @@ from redis.exceptions import ( from redis.typing import EncodableT from redis.utils import HIREDIS_AVAILABLE, str_if_bytes -from ..parsers import AsyncHiredisParser, AsyncRESP2Parser, BaseParser, Encoder +from ..parsers import AsyncHiredisParser, _AsyncRESP2Parser, BaseParser, Encoder SYM_STAR = b"*" SYM_DOLLAR = b"$" @@ -76,11 +76,11 @@ NO_AUTH_SET_ERROR = { } -DefaultParser: Type[Union[AsyncRESP2Parser, AsyncHiredisParser]] +DefaultParser: Type[Union[_AsyncRESP2Parser, AsyncHiredisParser]] if HIREDIS_AVAILABLE: DefaultParser = AsyncHiredisParser else: - DefaultParser = AsyncRESP2Parser + DefaultParser = _AsyncRESP2Parser class ConnectCallbackProtocol(Protocol): diff --git a/redis/connection.py b/redis/connection.py index 568c11c..a83714e 100755 --- a/redis/connection.py +++ b/redis/connection.py @@ -22,7 +22,7 @@ from .exceptions import ( ResponseError, TimeoutError, ) -from .parsers import Encoder, HiredisParser, RESP2Parser +from .parsers import Encoder, HiredisParser, _RESP2Parser from .retry import Retry from .utils import ( CRYPTOGRAPHY_AVAILABLE, @@ -56,11 +56,11 @@ NO_AUTH_SET_ERROR = { } -DefaultParser: Type[Union[RESP2Parser, HiredisParser]] +DefaultParser: Type[Union[_RESP2Parser, HiredisParser]] if HIREDIS_AVAILABLE: DefaultParser = HiredisParser else: - DefaultParser = RESP2Parser + DefaultParser = _RESP2Parser class Connection: diff --git a/redis/parsers/__init__.py b/redis/parsers/__init__.py index c6d950d..b80c30b 100644 --- a/redis/parsers/__init__.py +++ b/redis/parsers/__init__.py @@ -1,16 +1,16 @@ from .commands import AsyncCommandsParser, CommandsParser from .encoders import Encoder from .hiredis import AsyncHiredisParser, HiredisParser -from .protocol import BaseParser -from .resp2 import AsyncRESP2Parser, RESP2Parser +from .base import BaseParser +from .resp2 import _AsyncRESP2Parser, _RESP2Parser __all__ = [ "AsyncCommandsParser", "AsyncHiredisParser", - "AsyncRESP2Parser", + "_AsyncRESP2Parser", "CommandsParser", "Encoder", "BaseParser", "HiredisParser", - "RESP2Parser", + "_RESP2Parser", ] diff --git a/redis/parsers/protocol.py b/redis/parsers/base.py index 22c89ba..22c89ba 100644 --- a/redis/parsers/protocol.py +++ b/redis/parsers/base.py diff --git a/redis/parsers/hiredis.py b/redis/parsers/hiredis.py index 93f05ba..d84830a 100644 --- a/redis/parsers/hiredis.py +++ b/redis/parsers/hiredis.py @@ -1,6 +1,7 @@ import asyncio import socket -from typing import Callable, List, Optional, TypedDict, Union +from typing import Callable, List, Optional, Union +from redis.compat import TypedDict import async_timeout @@ -12,7 +13,7 @@ from ..exceptions import ( ) from ..typing import EncodableT from ..utils import HIREDIS_AVAILABLE -from .protocol import AsyncBaseParser, BaseParser +from .base import AsyncBaseParser, BaseParser from .socket import ( NONBLOCKING_EXCEPTION_ERROR_NUMBERS, NONBLOCKING_EXCEPTIONS, diff --git a/redis/parsers/resp2.py b/redis/parsers/resp2.py index 9a47040..7be1ec3 100644 --- a/redis/parsers/resp2.py +++ b/redis/parsers/resp2.py @@ -7,11 +7,11 @@ from redis.typing import EncodableT from ..exceptions import ConnectionError, InvalidResponse, RedisError, ResponseError from .encoders import Encoder -from .protocol import AsyncBaseParser, BaseParser +from .base import AsyncBaseParser, BaseParser from .socket import SERVER_CLOSED_CONNECTION_ERROR, SocketBuffer -class RESP2Parser(BaseParser): +class _RESP2Parser(BaseParser): "Plain Python parsing class" def __init__(self, socket_read_size): @@ -94,7 +94,7 @@ class RESP2Parser(BaseParser): return response -class AsyncRESP2Parser(AsyncBaseParser): +class _AsyncRESP2Parser(AsyncBaseParser): """Parsing class for the RESP2 protocol""" __slots__ = AsyncBaseParser.__slots__ + ("encoder",) diff --git a/tests/test_asyncio/conftest.py b/tests/test_asyncio/conftest.py index c011d60..f018b49 100644 --- a/tests/test_asyncio/conftest.py +++ b/tests/test_asyncio/conftest.py @@ -12,7 +12,7 @@ from redis.asyncio.client import Monitor from redis.asyncio.connection import parse_url from redis.asyncio.retry import Retry from redis.backoff import NoBackoff -from redis.parsers import AsyncHiredisParser, AsyncRESP2Parser +from redis.parsers import AsyncHiredisParser, _AsyncRESP2Parser from redis.utils import HIREDIS_AVAILABLE from tests.conftest import REDIS_INFO @@ -29,12 +29,12 @@ async def _get_info(redis_url): @pytest_asyncio.fixture( params=[ pytest.param( - (True, AsyncRESP2Parser), + (True, _AsyncRESP2Parser), marks=pytest.mark.skipif( 'config.REDIS_INFO["cluster_enabled"]', reason="cluster mode enabled" ), ), - (False, AsyncRESP2Parser), + (False, _AsyncRESP2Parser), pytest.param( (True, AsyncHiredisParser), marks=[ diff --git a/tests/test_asyncio/test_connection.py b/tests/test_asyncio/test_connection.py index 6d0d54e..0754fbf 100644 --- a/tests/test_asyncio/test_connection.py +++ b/tests/test_asyncio/test_connection.py @@ -9,7 +9,7 @@ from redis.asyncio.connection import Connection, UnixDomainSocketConnection from redis.asyncio.retry import Retry from redis.backoff import NoBackoff from redis.exceptions import ConnectionError, InvalidResponse, TimeoutError -from redis.parsers import AsyncRESP2Parser +from redis.parsers import _AsyncRESP2Parser from tests.conftest import skip_if_server_version_lt from .compat import mock @@ -21,8 +21,8 @@ async def test_invalid_response(create_redis): raw = b"x" - parser: "AsyncRESP2Parser" = r.connection._parser - if not isinstance(parser, AsyncRESP2Parser): + parser: "_AsyncRESP2Parser" = r.connection._parser + if not isinstance(parser, _AsyncRESP2Parser): pytest.skip("PythonParser only") stream_mock = mock.Mock(parser._stream) stream_mock.readline.return_value = raw + b"\r\n" diff --git a/tests/test_asyncio/test_encoding.py b/tests/test_asyncio/test_encoding.py index 18cfdd8..9f7c7af 100644 --- a/tests/test_asyncio/test_encoding.py +++ b/tests/test_asyncio/test_encoding.py @@ -95,7 +95,6 @@ class TestCommandsAreNotEncoded: class TestInvalidUserInput: - async def test_none_fails(self, r: redis.Redis): with pytest.raises(DataError): await r.set("a", None) # type: ignore diff --git a/tests/test_asyncio/test_pubsub.py b/tests/test_asyncio/test_pubsub.py index 0ca05e9..08d8c19 100644 --- a/tests/test_asyncio/test_pubsub.py +++ b/tests/test_asyncio/test_pubsub.py @@ -991,7 +991,7 @@ class TestBaseException: assert msg is not None # timeout waiting for another message which never arrives assert pubsub.connection.is_connected - with patch("redis.parsers.AsyncRESP2Parser.read_response") as mock1: + with patch("redis.parsers._AsyncRESP2Parser.read_response") as mock1: mock1.side_effect = BaseException("boom") with patch("redis.parsers.AsyncHiredisParser.read_response") as mock2: mock2.side_effect = BaseException("boom") diff --git a/tests/test_encoding.py b/tests/test_encoding.py index e1e33f8..0b2d1b4 100644 --- a/tests/test_encoding.py +++ b/tests/test_encoding.py @@ -97,7 +97,6 @@ class TestCommandsAreNotEncoded: class TestInvalidUserInput: - def test_none_fails(self, r): with pytest.raises(redis.DataError): r.set("a", None) diff --git a/tests/test_pubsub.py b/tests/test_pubsub.py index d131ff7..e6666e4 100644 --- a/tests/test_pubsub.py +++ b/tests/test_pubsub.py @@ -767,7 +767,7 @@ class TestBaseException: assert msg is not None # timeout waiting for another message which never arrives assert is_connected() - with patch("redis.parsers.RESP2Parser.read_response") as mock1: + with patch("redis.parsers._RESP2Parser.read_response") as mock1: mock1.side_effect = BaseException("boom") with patch("redis.parsers.HiredisParser.read_response") as mock2: mock2.side_effect = BaseException("boom") |
