From a7a5042bed89b96fa2e391f3be0e255a59bffb0a Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Thu, 8 Aug 2024 10:21:23 +0200 Subject: [PATCH] Deprecate fully websockets.http. All public API within this module are deprecated since version 9.0 so there's nothing to document. --- src/websockets/connection.py | 1 - src/websockets/http.py | 31 ++++++++++--------------------- tests/test_http.py | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 22 deletions(-) create mode 100644 tests/test_http.py diff --git a/src/websockets/connection.py b/src/websockets/connection.py index 88bcda1aa..7942c1a28 100644 --- a/src/websockets/connection.py +++ b/src/websockets/connection.py @@ -2,7 +2,6 @@ import warnings -# lazy_import doesn't support this use case. from .protocol import SEND_EOF, Protocol as Connection, Side, State # noqa: F401 diff --git a/src/websockets/http.py b/src/websockets/http.py index a24102307..3dc560062 100644 --- a/src/websockets/http.py +++ b/src/websockets/http.py @@ -1,26 +1,15 @@ from __future__ import annotations -import typing +import warnings -from .imports import lazy_import +from .datastructures import Headers, MultipleValuesError # noqa: F401 +from .legacy.http import read_request, read_response # noqa: F401 -# For backwards compatibility: - - -# When type checking, import non-deprecated aliases eagerly. Else, import on demand. -if typing.TYPE_CHECKING: - from .datastructures import Headers, MultipleValuesError # noqa: F401 -else: - lazy_import( - globals(), - # Headers and MultipleValuesError used to be defined in this module. - aliases={ - "Headers": ".datastructures", - "MultipleValuesError": ".datastructures", - }, - deprecated_aliases={ - "read_request": ".legacy.http", - "read_response": ".legacy.http", - }, - ) +warnings.warn( + "Headers and MultipleValuesError were moved " + "from websockets.http to websockets.datastructures" + "and read_request and read_response were moved " + "from websockets.http to websockets.legacy.http", + DeprecationWarning, +) diff --git a/tests/test_http.py b/tests/test_http.py new file mode 100644 index 000000000..6e81199fc --- /dev/null +++ b/tests/test_http.py @@ -0,0 +1,16 @@ +from websockets.datastructures import Headers + +from .utils import DeprecationTestCase + + +class BackwardsCompatibilityTests(DeprecationTestCase): + def test_headers_class(self): + with self.assertDeprecationWarning( + "Headers and MultipleValuesError were moved " + "from websockets.http to websockets.datastructures" + "and read_request and read_response were moved " + "from websockets.http to websockets.legacy.http", + ): + from websockets.http import Headers as OldHeaders + + self.assertIs(OldHeaders, Headers)