Skip to content

Commit eb35d4b

Browse files
committed
docs: display Protocol in ProtocolBase member cross-references (#1103)
The owner refined the #1103 ruling: a `ProtocolBase.<member>` reference should read `Protocol.<member>` in the rendered docs, for one consistent public vocabulary, while the link still targets the `ProtocolBase` attribute. That is the split-display-target form, `:meth:`Protocol.X <...protocol.ProtocolBase.X>``, applied across everything Sphinx renders. * 46 reference sites in `pcapkit/` and `docs/source/` now display `Protocol.<member>`. 37 keep their `ProtocolBase` target, which is the requested form; the other 9 already targeted `Protocol` -- #2420 moved those targets but left the display text reading `ProtocolBase` -- and are now display-consistent too. * Three short-form references in `protocol.py` gained an explicit fully-qualified target, so the display text could change without repointing the link: `:meth:`ProtocolBase._parse_next_layer`` is now `:meth:`Protocol._parse_next_layer <...ProtocolBase._parse_next_layer>``. * `__init_subclass__` keeps displaying `ProtocolBase` (6 sites). `Protocol` defines its own override, so displaying `Protocol` there would name a different method than the link resolves to. * Two further sites keep `ProtocolBase` because the adjacent prose would otherwise contradict itself: `schema.py`'s comment reads "``ProtocolBase``, not ``Protocol``" two lines above its reference, and `protocol-layer-placement.rst` asserts `OSPF.__proto__` *is* that attribute inside a paragraph analysing MRO set-difference. * The `Raises:` clause of `register` is unchanged. It names the class the guard's `issubclass` actually tests, not a member whose documentation is being pointed at, and `tests/protocols/test_register_class_guard_unit.py` asserts that wording (#2316/#1016). * `tests/` and `examples/` are untouched (28 sites). Their docstrings are not part of the Sphinx render, so the display rationale does not reach them. No link was repointed: a guard canonicalises every role target before and after and reports them identical, bar the three short-form expansions, which resolve to the same object. An AST-structure guard (`ast.dump` with docstrings stripped) confirms all 26 touched `.py` files are prose-only.
1 parent 867616b commit eb35d4b

29 files changed

Lines changed: 52 additions & 47 deletions

File tree

‎docs/source/ext.rst‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,13 @@ The following code snippet shows how to create a new protocol class:
241241
silently wrong field. The accepted set is read from :func:`inspect.signature` -- the union of every
242242
keyword-taking parameter of ``make``, ``read``, ``pack``, ``unpack``,
243243
``__post_init__`` and ``__init__`` anywhere in the class's MRO -- which is
244-
wider than ``make`` alone because :meth:`ProtocolBase.__post_init__
244+
wider than ``make`` alone because :meth:`Protocol.__post_init__
245245
<pcapkit.protocols.protocol.ProtocolBase.__post_init__>` hands the same
246246
``**kwargs`` to the construction and to the parse, so a keyword only ``read``
247247
declares still travels through ``make``.
248248

249249
Shapes a signature cannot express are declared on the class instead, via
250-
:attr:`ProtocolBase.__keywords__
250+
:attr:`Protocol.__keywords__
251251
<pcapkit.protocols.protocol.ProtocolBase.__keywords__>`:
252252

253253
.. code-block:: python
@@ -271,7 +271,7 @@ The following code snippet shows how to create a new protocol class:
271271
subclass of a dispatcher is checked normally. Prefer a declared parameter to
272272
either: it is also what documents the keyword to your callers.
273273

274-
Parsing is unaffected. :meth:`ProtocolBase.from_data
274+
Parsing is unaffected. :meth:`Protocol.from_data
275275
<pcapkit.protocols.protocol.ProtocolBase.from_data>` checks the keywords its
276276
caller passes just as strictly, raising
277277
:exc:`~pcapkit.utilities.exceptions.UnsupportedCall`, but only warns with
@@ -281,7 +281,7 @@ The following code snippet shows how to create a new protocol class:
281281

282282
.. warning::
283283

284-
The check lives in :meth:`ProtocolBase.__init__
284+
The check lives in :meth:`Protocol.__init__
285285
<pcapkit.protocols.protocol.ProtocolBase.__init__>`, where every producer's
286286
keywords converge, so it covers ``SomeProtocol(...)`` and the ``pack`` it
287287
leads to -- but **not** a direct ``SomeProtocol.make(...)`` call, which still

‎docs/source/pcapkit/protocols/internet/ipv6_ext.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ This class is reached in these ways:
141141
``IPv6-Route``, ``IPv6-Opts``, ``MH``, ``HIP``, ``IPv6-Frag`` and ``AH`` all
142142
have dedicated classes. When one of *those* raises,
143143
:func:`~pcapkit.corekit.decorators.beholder`
144-
(:meth:`ProtocolBase._import_next_layer <pcapkit.protocols.protocol.ProtocolBase._import_next_layer>`)
144+
(:meth:`Protocol._import_next_layer <pcapkit.protocols.protocol.ProtocolBase._import_next_layer>`)
145145
would substitute plain :class:`~pcapkit.protocols.misc.raw.Raw`, which loses
146146
``next`` and crashes the walk as in path 1.
147147
:meth:`IPv6._import_next_layer <pcapkit.protocols.internet.ipv6.IPv6._import_next_layer>` catches

‎docs/source/pcapkit/utilities/chardet.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Character Set Detection
77
turning the bytes of a text field into a :obj:`str`. It is shared by
88
:meth:`StringField.post_process
99
<pcapkit.corekit.fields.strings.StringField.post_process>` and
10-
:meth:`ProtocolBase.decode <pcapkit.protocols.protocol.Protocol.decode>`,
10+
:meth:`Protocol.decode <pcapkit.protocols.protocol.Protocol.decode>`,
1111
which is why it lives here rather than beside either of them.
1212

1313
.. autofunction:: pcapkit.utilities.chardet.detect

‎pcapkit/corekit/decorators.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
#: contextvars.ContextVar[bool]: Whether a call :func:`beholder` wraps is under
5858
#: way, so that an :exc:`Exception` raised inside it ends with the layer that
59-
#: raised replaced; see :meth:`ProtocolBase._parse_next_layer
59+
#: raised replaced; see :meth:`Protocol._parse_next_layer
6060
#: <pcapkit.protocols.protocol.ProtocolBase._parse_next_layer>` (:issue:`2308`).
6161
_beholding = contextvars.ContextVar('_beholding', default=False)
6262

@@ -116,7 +116,7 @@ def beholder(
116116
:class:`~pcapkit.protocols.misc.null.NoPayload`, if the error is an
117117
end-of-file :exc:`~pcapkit.utilities.exceptions.StructError`.
118118
119-
When :meth:`ProtocolBase._parse_next_layer
119+
When :meth:`Protocol._parse_next_layer
120120
<pcapkit.protocols.protocol.ProtocolBase._parse_next_layer>` held the
121121
warnings of the layer that raised, they are dropped with it: they describe a
122122
layer the result does not have, and the replacement's ``error`` reports the

‎pcapkit/corekit/fields/numbers.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ def post_process(self, value: 'int | bytes', packet: 'dict[str, Any]') -> 'Stdli
730730
the registry with ``aenum.extend_enum``, for two reasons: a
731731
capture carrying many distinct unassigned codes would otherwise grow
732732
a process-global registry without bound, which is the growth
733-
:meth:`ProtocolBase._lookup_registry
733+
:meth:`Protocol._lookup_registry
734734
<pcapkit.protocols.protocol.ProtocolBase._lookup_registry>` exists
735735
to avoid; and a stdlib :class:`enum.IntEnum` registry is then
736736
handled exactly like an ``aenum.IntEnum`` one.

‎pcapkit/corekit/module.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def klass(self) -> 'Type[_T]':
6060
The module is read from :data:`sys.modules` first, and
6161
:func:`importlib.import_module` is entered only when it is not
6262
loaded yet. That matters because this property is on a *per-frame*
63-
dispatch path: :meth:`ProtocolBase._lookup_next_layer
63+
dispatch path: :meth:`Protocol._lookup_next_layer
6464
<pcapkit.protocols.protocol.ProtocolBase._lookup_next_layer>`
6565
deliberately writes no resolved class back, so every next layer
6666
lookup resolves its descriptor again -- the one registered for the

‎pcapkit/corekit/sentinels.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ def __bool__(self) -> 'Literal[False]':
571571
#: own ``__keywords__`` out of its :attr:`~object.__dict__`, where
572572
#: :obj:`None` is itself a meaningful value -- the opt-out that says the
573573
#: class cannot enumerate its keywords, cf.
574-
#: :attr:`ProtocolBase.__keywords__
574+
#: :attr:`Protocol.__keywords__
575575
#: <pcapkit.protocols.protocol.ProtocolBase.__keywords__>`. Never leaves
576576
#: :mod:`pcapkit.protocols.protocol`, which imports it from here for exactly
577577
#: that one read. Private by documentation rather than by a

‎pcapkit/foundation/engines/dpkt.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def read_frame(self) -> 'DPKTPacket':
551551
try:
552552
packet = protocol(pkt) # type: DPKTPacket
553553
except Exception as exc: # pylint: disable=broad-except
554-
# NOTE: Caught broadly, as :meth:`ProtocolBase.analyze
554+
# NOTE: Caught broadly, as :meth:`Protocol.analyze
555555
# <pcapkit.protocols.protocol.ProtocolBase.analyze>` does: dpkt raises
556556
# more than its own ``UnpackError`` while parsing -- dpkt 1.9.8 reads
557557
# ``frag_off`` from whatever header follows an IPv6 Fragment header,

‎pcapkit/protocols/application/application.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def from_data(cls, data: '_PT | dict[str, Any]', **kwargs: 'Any') -> 'Self':
121121
122122
Args:
123123
data: Protocol data.
124-
**kwargs: Construction keywords, as for :meth:`ProtocolBase.from_data
124+
**kwargs: Construction keywords, as for :meth:`Protocol.from_data
125125
<pcapkit.protocols.protocol.ProtocolBase.from_data>`.
126126
127127
Returns:

‎pcapkit/protocols/application/http.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def from_data(cls, data: '_PT | dict[str, Any]', **kwargs: 'Any') -> 'Self':
404404
into the versioned data model its keys belong to -- ``receipt``
405405
is HTTP/1.*'s and ``sid`` HTTP/2's -- since this class's own data
406406
model carries no version.
407-
**kwargs: As :meth:`ProtocolBase.from_data
407+
**kwargs: As :meth:`Protocol.from_data
408408
<pcapkit.protocols.protocol.ProtocolBase.from_data>`.
409409
410410
Returns:

0 commit comments

Comments
 (0)