From c12561db0a16156d991774181680616fc31f9b54 Mon Sep 17 00:00:00 2001 From: lowercase00 <21188280+lowercase00@users.noreply.github.com> Date: Tue, 7 Mar 2023 23:37:39 -0300 Subject: docs: add deprecation warnings to connection functions (#1860) --- rq/connections.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'rq') diff --git a/rq/connections.py b/rq/connections.py index 2c6d227..792eb4f 100644 --- a/rq/connections.py +++ b/rq/connections.py @@ -1,6 +1,7 @@ +import warnings from contextlib import contextmanager from typing import Optional -import warnings + from redis import Redis from .local import LocalStack @@ -31,7 +32,8 @@ def Connection(connection: Optional['Redis'] = None): # noqa connection (Optional[Redis], optional): A Redis Connection instance. Defaults to None. """ warnings.warn( - "The Conneciton context manager is deprecated. Use the `connection` parameter instead.", DeprecationWarning + "The Conneciton context manager is deprecated. Use the `connection` parameter instead.", + DeprecationWarning, ) if connection is None: connection = Redis() @@ -41,7 +43,8 @@ def Connection(connection: Optional['Redis'] = None): # noqa finally: popped = pop_connection() assert popped == connection, ( - 'Unexpected Redis connection was popped off the stack. ' 'Check your Redis connection setup.' + 'Unexpected Redis connection was popped off the stack. ' + 'Check your Redis connection setup.' ) @@ -52,6 +55,10 @@ def push_connection(redis: 'Redis'): Args: redis (Redis): A Redis connection """ + warnings.warn( + "The `push_connection` function is deprecated. Pass the `connection` explicitly instead.", + DeprecationWarning, + ) _connection_stack.push(redis) @@ -62,6 +69,10 @@ def pop_connection() -> 'Redis': Returns: redis (Redis): A Redis connection """ + warnings.warn( + "The `pop_connection` function is deprecated. Pass the `connection` explicitly instead.", + DeprecationWarning, + ) return _connection_stack.pop() @@ -73,6 +84,10 @@ def get_current_connection() -> 'Redis': Returns: Redis: A Redis Connection """ + warnings.warn( + "The `get_current_connection` function is deprecated. Pass the `connection` explicitly instead.", + DeprecationWarning, + ) return _connection_stack.top @@ -90,7 +105,10 @@ def resolve_connection(connection: Optional['Redis'] = None) -> 'Redis': Returns: Redis: A Redis Connection """ - + warnings.warn( + "The `resolve_connection` function is deprecated. Pass the `connection` explicitly instead.", + DeprecationWarning, + ) if connection is not None: return connection @@ -102,4 +120,6 @@ def resolve_connection(connection: Optional['Redis'] = None) -> 'Redis': _connection_stack = LocalStack() + __all__ = ['Connection', 'get_current_connection', 'push_connection', 'pop_connection'] + -- cgit v1.2.1