Skip to content

Commit a7a5042

Browse files
committed
Deprecate fully websockets.http.
All public API within this module are deprecated since version 9.0 so there's nothing to document.
1 parent bbb3161 commit a7a5042

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

src/websockets/connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import warnings
44

5-
# lazy_import doesn't support this use case.
65
from .protocol import SEND_EOF, Protocol as Connection, Side, State # noqa: F401
76

87

src/websockets/http.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
from __future__ import annotations
22

3-
import typing
3+
import warnings
44

5-
from .imports import lazy_import
5+
from .datastructures import Headers, MultipleValuesError # noqa: F401
6+
from .legacy.http import read_request, read_response # noqa: F401
67

78

8-
# For backwards compatibility:
9-
10-
11-
# When type checking, import non-deprecated aliases eagerly. Else, import on demand.
12-
if typing.TYPE_CHECKING:
13-
from .datastructures import Headers, MultipleValuesError # noqa: F401
14-
else:
15-
lazy_import(
16-
globals(),
17-
# Headers and MultipleValuesError used to be defined in this module.
18-
aliases={
19-
"Headers": ".datastructures",
20-
"MultipleValuesError": ".datastructures",
21-
},
22-
deprecated_aliases={
23-
"read_request": ".legacy.http",
24-
"read_response": ".legacy.http",
25-
},
26-
)
9+
warnings.warn(
10+
"Headers and MultipleValuesError were moved "
11+
"from websockets.http to websockets.datastructures"
12+
"and read_request and read_response were moved "
13+
"from websockets.http to websockets.legacy.http",
14+
DeprecationWarning,
15+
)

tests/test_http.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from websockets.datastructures import Headers
2+
3+
from .utils import DeprecationTestCase
4+
5+
6+
class BackwardsCompatibilityTests(DeprecationTestCase):
7+
def test_headers_class(self):
8+
with self.assertDeprecationWarning(
9+
"Headers and MultipleValuesError were moved "
10+
"from websockets.http to websockets.datastructures"
11+
"and read_request and read_response were moved "
12+
"from websockets.http to websockets.legacy.http",
13+
):
14+
from websockets.http import Headers as OldHeaders
15+
16+
self.assertIs(OldHeaders, Headers)

0 commit comments

Comments
 (0)