diff --git a/docs/api/client.rst b/docs/api/client.rst index f969227a9..db8cbc914 100644 --- a/docs/api/client.rst +++ b/docs/api/client.rst @@ -1,7 +1,7 @@ Client ====== -.. automodule:: websockets.legacy.client +.. automodule:: websockets.client Opening a connection -------------------- diff --git a/docs/api/index.rst b/docs/api/index.rst index 20bb740b3..0a616cbce 100644 --- a/docs/api/index.rst +++ b/docs/api/index.rst @@ -46,5 +46,10 @@ both in the client API and server API. utilities All public APIs can be imported from the :mod:`websockets` package, unless -noted otherwise. Anything that isn't listed in this API documentation is a -private API, with no guarantees of behavior or backwards-compatibility. +noted otherwise. This convenience feature is incompatible with static code +analysis tools such as mypy_, though. + +.. _mypy: https://github.com/python/mypy + +Anything that isn't listed in this API documentation is a private API. There's +no guarantees of behavior or backwards-compatibility for private APIs. diff --git a/docs/api/server.rst b/docs/api/server.rst index 16c8f6359..9e7b801a9 100644 --- a/docs/api/server.rst +++ b/docs/api/server.rst @@ -1,7 +1,7 @@ Server ====== -.. automodule:: websockets.legacy.server +.. automodule:: websockets.server Starting a server ----------------- @@ -90,7 +90,7 @@ Server Basic authentication -------------------- -.. automodule:: websockets.legacy.auth +.. automodule:: websockets.auth .. autofunction:: basic_auth_protocol_factory diff --git a/docs/changelog.rst b/docs/changelog.rst index fb40aee2a..218bbec3d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -37,6 +37,8 @@ They may change at any time. * Restored compatibility of ``python -m websockets`` with Python < 3.9. +* Restored compatibility with mypy. + 9.0.1 ..... @@ -73,6 +75,20 @@ They may change at any time. but that never happened. Keeping these APIs public makes it more difficult to improve websockets for no actual benefit. +.. note:: + + **Version 9.0 may require changes if you use static code analysis tools.** + + Convenience imports from the ``websockets`` module are performed lazily. + While this is supported by Python, static code analysis tools such as mypy + are unable to understand the behavior. + + If you depend on such tools, use the real import path, which can be found + in the API documentation:: + + from websockets.client import connect + from websockets.server import serve + * Added compatibility with Python 3.9. * Added support for IRIs in addition to URIs. diff --git a/docs/extensions.rst b/docs/extensions.rst index 042ed3d9a..f5e2f497f 100644 --- a/docs/extensions.rst +++ b/docs/extensions.rst @@ -14,9 +14,8 @@ specification, WebSocket Per-Message Deflate, specified in :rfc:`7692`. Per-Message Deflate ------------------- -:func:`~websockets.legacy.client.connect` and -:func:`~websockets.legacy.server.serve` enable the Per-Message Deflate -extension by default. +:func:`~websockets.client.connect` and :func:`~websockets.server.serve` enable +the Per-Message Deflate extension by default. If you want to disable it, set ``compression=None``:: diff --git a/src/websockets/auth.py b/src/websockets/auth.py new file mode 100644 index 000000000..f97c1feb0 --- /dev/null +++ b/src/websockets/auth.py @@ -0,0 +1,2 @@ +# See #940 for why lazy_import isn't used here for backwards compatibility. +from .legacy.auth import * # noqa diff --git a/src/websockets/client.py b/src/websockets/client.py index 91dd1662e..0ddf19f00 100644 --- a/src/websockets/client.py +++ b/src/websockets/client.py @@ -24,7 +24,6 @@ ) from .http import USER_AGENT, build_host from .http11 import Request, Response -from .imports import lazy_import from .typing import ( ConnectionOption, ExtensionHeader, @@ -36,14 +35,9 @@ from .utils import accept_key, generate_key -lazy_import( - globals(), - aliases={ - "connect": ".legacy.client", - "unix_connect": ".legacy.client", - "WebSocketClientProtocol": ".legacy.client", - }, -) +# See #940 for why lazy_import isn't used here for backwards compatibility. +from .legacy.client import * # isort:skip # noqa + __all__ = ["ClientConnection"] diff --git a/src/websockets/server.py b/src/websockets/server.py index 67ab83031..f57d36b70 100644 --- a/src/websockets/server.py +++ b/src/websockets/server.py @@ -26,7 +26,6 @@ ) from .http import USER_AGENT from .http11 import Request, Response -from .imports import lazy_import from .typing import ( ConnectionOption, ExtensionHeader, @@ -37,15 +36,8 @@ from .utils import accept_key -lazy_import( - globals(), - aliases={ - "serve": ".legacy.server", - "unix_serve": ".legacy.server", - "WebSocketServerProtocol": ".legacy.server", - "WebSocketServer": ".legacy.server", - }, -) +# See #940 for why lazy_import isn't used here for backwards compatibility. +from .legacy.server import * # isort:skip # noqa __all__ = ["ServerConnection"]