Skip to content

Commit cb88119

Browse files
committed
Review reference docs.
Remove sphinx-autodoc-typehints and use native autodoc features instead, mainly because I can't find a workaround for: https://github.com/agronholm/sphinx-autodoc-typehints/issues/132 Re-introduce the "common" docs, else linking to send() and recv() is a mess.
1 parent 88ae5eb commit cb88119

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1467
-1244
lines changed

docs/conf.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,52 @@
3131

3232
# -- General configuration ---------------------------------------------------
3333

34+
nitpicky = True
35+
36+
nitpick_ignore = [
37+
# topics/design.rst discusses undocumented APIs
38+
("py:meth", "client.WebSocketClientProtocol.handshake"),
39+
("py:meth", "server.WebSocketServerProtocol.handshake"),
40+
("py:attr", "legacy.protocol.WebSocketCommonProtocol.is_client"),
41+
("py:attr", "legacy.protocol.WebSocketCommonProtocol.messages"),
42+
("py:meth", "legacy.protocol.WebSocketCommonProtocol.close_connection"),
43+
("py:attr", "legacy.protocol.WebSocketCommonProtocol.close_connection_task"),
44+
("py:meth", "legacy.protocol.WebSocketCommonProtocol.keepalive_ping"),
45+
("py:attr", "legacy.protocol.WebSocketCommonProtocol.keepalive_ping_task"),
46+
("py:meth", "legacy.protocol.WebSocketCommonProtocol.transfer_data"),
47+
("py:attr", "legacy.protocol.WebSocketCommonProtocol.transfer_data_task"),
48+
("py:meth", "legacy.protocol.WebSocketCommonProtocol.connection_open"),
49+
("py:meth", "legacy.protocol.WebSocketCommonProtocol.ensure_open"),
50+
("py:meth", "legacy.protocol.WebSocketCommonProtocol.fail_connection"),
51+
("py:meth", "legacy.protocol.WebSocketCommonProtocol.connection_lost"),
52+
("py:meth", "legacy.protocol.WebSocketCommonProtocol.read_message"),
53+
("py:meth", "legacy.protocol.WebSocketCommonProtocol.write_frame"),
54+
]
55+
3456
# Add any Sphinx extension module names here, as strings. They can be
3557
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3658
# ones.
3759
extensions = [
3860
"sphinx.ext.autodoc",
3961
"sphinx.ext.intersphinx",
4062
"sphinx.ext.linkcode",
41-
"sphinx_autodoc_typehints",
63+
"sphinx.ext.napoleon",
4264
"sphinx_copybutton",
4365
"sphinx_inline_tabs",
4466
"sphinxcontrib.spelling",
4567
"sphinxcontrib_trio",
4668
"sphinxext.opengraph",
4769
]
4870

71+
autodoc_typehints = "description"
72+
73+
autodoc_typehints_description_target = "documented"
74+
75+
# Workaround for https://github.com/sphinx-doc/sphinx/issues/9560
76+
from sphinx.domains.python import PythonDomain
77+
assert PythonDomain.object_types['data'].roles == ('data', 'obj')
78+
PythonDomain.object_types['data'].roles = ('data', 'class', 'obj')
79+
4980
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
5081

5182
spelling_show_suggestions = True

docs/howto/cheatsheet.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@ Server
2626
:meth:`~legacy.protocol.WebSocketCommonProtocol.pong` if you wish but it isn't
2727
needed in general.
2828

29-
* Create a server with :func:`~legacy.server.serve` which is similar to asyncio's
30-
:meth:`~asyncio.AbstractEventLoop.create_server`. You can also use it as an
31-
asynchronous context manager.
29+
* Create a server with :func:`~server.serve` which is similar to asyncio's
30+
:meth:`~asyncio.loop.create_server`. You can also use it as an asynchronous
31+
context manager.
3232

3333
* The server takes care of establishing connections, then lets the handler
3434
execute the application logic, and finally closes the connection after the
3535
handler exits normally or with an exception.
3636

3737
* For advanced customization, you may subclass
38-
:class:`~legacy.server.WebSocketServerProtocol` and pass either this subclass or
38+
:class:`~server.WebSocketServerProtocol` and pass either this subclass or
3939
a factory function as the ``create_protocol`` argument.
4040

4141
Client
4242
------
4343

44-
* Create a client with :func:`~legacy.client.connect` which is similar to asyncio's
45-
:meth:`~asyncio.BaseEventLoop.create_connection`. You can also use it as an
44+
* Create a client with :func:`~client.connect` which is similar to asyncio's
45+
:meth:`~asyncio.loop.create_connection`. You can also use it as an
4646
asynchronous context manager.
4747

4848
* For advanced customization, you may subclass
49-
:class:`~legacy.server.WebSocketClientProtocol` and pass either this subclass or
49+
:class:`~client.WebSocketClientProtocol` and pass either this subclass or
5050
a factory function as the ``create_protocol`` argument.
5151

5252
* Call :meth:`~legacy.protocol.WebSocketCommonProtocol.recv` and
@@ -57,7 +57,7 @@ Client
5757
:meth:`~legacy.protocol.WebSocketCommonProtocol.pong` if you wish but it isn't
5858
needed in general.
5959

60-
* If you aren't using :func:`~legacy.client.connect` as a context manager, call
60+
* If you aren't using :func:`~client.connect` as a context manager, call
6161
:meth:`~legacy.protocol.WebSocketCommonProtocol.close` to terminate the connection.
6262

6363
.. _debugging:

docs/howto/django.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ support asynchronous I/O. It would block the event loop if it didn't run in a
124124
separate thread. :func:`~asyncio.to_thread` is available since Python 3.9. In
125125
earlier versions, use :meth:`~asyncio.loop.run_in_executor` instead.
126126

127-
Finally, we start a server with :func:`~websockets.serve`.
127+
Finally, we start a server with :func:`~websockets.server.serve`.
128128

129129
We're ready to test!
130130

docs/howto/extensions.rst

+7-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ Writing an extension
44
.. currentmodule:: websockets.extensions
55

66
During the opening handshake, WebSocket clients and servers negotiate which
7-
extensions will be used with which parameters. Then each frame is processed by
8-
extensions before being sent or after being received.
7+
extensions_ will be used with which parameters. Then each frame is processed
8+
by extensions before being sent or after being received.
9+
10+
.. _extensions: https://www.rfc-editor.org/rfc/rfc6455.html#section-9
911

1012
As a consequence, writing an extension requires implementing several classes:
1113

@@ -23,11 +25,8 @@ As a consequence, writing an extension requires implementing several classes:
2325
Extensions are initialized by extension factories, so they don't need to be
2426
part of the public API of an extension.
2527

26-
websockets provides abstract base classes for extension factories and
27-
extensions. See the API documentation for details on their methods:
28-
29-
* :class:`ClientExtensionFactory` and :class:`ServerExtensionFactory` for
30-
extension factories,
31-
* :class:`Extension` for extensions.
28+
websockets provides base classes for extension factories and extensions.
29+
See :class:`ClientExtensionFactory`, :class:`ServerExtensionFactory`,
30+
and :class:`Extension` for details.
3231

3332

docs/howto/faq.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FAQ
55

66
.. note::
77

8-
Many questions asked in :mod:`websockets`' issue tracker are actually
8+
Many questions asked in websockets' issue tracker are actually
99
about :mod:`asyncio`. Python's documentation about `developing with
1010
asyncio`_ is a good complement.
1111

@@ -99,13 +99,13 @@ How do I get access HTTP headers, for example cookies?
9999
......................................................
100100

101101
To access HTTP headers during the WebSocket handshake, you can override
102-
:attr:`~legacy.server.WebSocketServerProtocol.process_request`::
102+
:attr:`~server.WebSocketServerProtocol.process_request`::
103103

104104
async def process_request(self, path, request_headers):
105105
cookies = request_header["Cookie"]
106106

107107
Once the connection is established, they're available in
108-
:attr:`~legacy.protocol.WebSocketServerProtocol.request_headers`::
108+
:attr:`~server.WebSocketServerProtocol.request_headers`::
109109

110110
async def handler(websocket, path):
111111
cookies = websocket.request_headers["Cookie"]
@@ -123,7 +123,7 @@ How do I set which IP addresses my server listens to?
123123

124124
Look at the ``host`` argument of :meth:`~asyncio.loop.create_server`.
125125

126-
:func:`serve` accepts the same arguments as
126+
:func:`~server.serve` accepts the same arguments as
127127
:meth:`~asyncio.loop.create_server`.
128128

129129
How do I close a connection properly?
@@ -143,7 +143,7 @@ Providing a HTTP server is out of scope for websockets. It only aims at
143143
providing a WebSocket server.
144144

145145
There's limited support for returning HTTP responses with the
146-
:attr:`~legacy.server.WebSocketServerProtocol.process_request` hook.
146+
:attr:`~server.WebSocketServerProtocol.process_request` hook.
147147

148148
If you need more, pick a HTTP server and run it separately.
149149

@@ -169,7 +169,7 @@ change it to::
169169
How do I close a connection properly?
170170
.....................................
171171

172-
The easiest is to use :func:`connect` as a context manager::
172+
The easiest is to use :func:`~client.connect` as a context manager::
173173

174174
async with connect(...) as websocket:
175175
...
@@ -196,7 +196,7 @@ How do I disable TLS/SSL certificate verification?
196196

197197
Look at the ``ssl`` argument of :meth:`~asyncio.loop.create_connection`.
198198

199-
:func:`connect` accepts the same arguments as
199+
:func:`~client.connect` accepts the same arguments as
200200
:meth:`~asyncio.loop.create_connection`.
201201

202202
asyncio usage
@@ -449,4 +449,4 @@ I'm having problems with threads
449449

450450
You shouldn't use threads. Use tasks instead.
451451

452-
:func:`~asyncio.AbstractEventLoop.call_soon_threadsafe` may help.
452+
:meth:`~asyncio.loop.call_soon_threadsafe` may help.

docs/intro/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ This client needs a context because the server uses a self-signed certificate.
8282

8383
A client connecting to a secure WebSocket server with a valid certificate
8484
(i.e. signed by a CA that your Python installation trusts) can simply pass
85-
``ssl=True`` to :func:`connect` instead of building a context.
85+
``ssl=True`` to :func:`~client.connect` instead of building a context.
8686

8787
Browser-based example
8888
---------------------

0 commit comments

Comments
 (0)