Skip to content

Commit

Permalink
Deprecate fully websockets.http.
Browse files Browse the repository at this point in the history
All public API within this module are deprecated since version 9.0
so there's nothing to document.
  • Loading branch information
aaugustin committed Aug 8, 2024
1 parent bbb3161 commit a7a5042
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/websockets/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
31 changes: 10 additions & 21 deletions src/websockets/http.py
Original file line number Diff line number Diff line change
@@ -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,
)
16 changes: 16 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit a7a5042

Please sign in to comment.