Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions docs/source/contributing/conventions/protocol-member-order.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Protocol Member Order
---------------------

The order of members inside a protocol class body. Settled by the owner as a
ruling, so a new dissector and a refactor land in the same layout.
The order of members inside a protocol class body. Settled by the owner on
:issue:`2490`, so a new dissector and a refactor land in the same layout.

Each group sits under its section comment, spelled as the repo spells it:
``# Properties.``, ``# Methods.``, ``# Data models.`` and ``# Utilities.``
Expand All @@ -17,7 +17,7 @@ The Order
``register_xxx()``.
#. **Data models.** Every dunder name: ``__index__``, ``__length_hint__``,
``__init__``, ``__new__``, ``__post_init__`` and any other.
#. **Utilities.** Everything else, mostly private methods, in three subgroups. Every private helper, including ``_check_*``, sits here, never before ``_make_data()``.
#. **Utilities.** Everything else, mostly private methods, in the subgroups below. Every private helper, including ``_check_*``, sits here, never before ``_make_data()``.

a. **Data.** ``_make_data()`` comes first in the group, before everything else.
b. **Helpers.** The helpers that ``read()`` or ``make()`` call, one helper at a
Expand All @@ -26,17 +26,33 @@ The Order
through ``getattr``, or through the registry maps (``__proto__``,
``__option__``, ``__parameter__`` and similar), do not count. They are ordered
by the enum value order of the corresponding code, or by the registry's order
where there is no enum. Each helper's
where there is no enum. A registry fallback that ``read()`` or ``make()``
names directly, such as ``_read_msg_unknown()`` in
:class:`~pcapkit.protocols.internet.mh.MH`, does not count either: it is a
specific reader, ruled on :issue:`2490`. Each helper's
``_read_`` and ``_make_`` methods stay together, with the reader first:
``_read_mac_addr()`` then ``_make_mac_addr()``.
c. **Specific readers and makers.** The option, type and parameter methods,
all ``_read_*()`` before all ``_make_*()``. Each set is ordered by the enum
value of the code or type it handles, not alphabetically by name.
all ``_read_*()`` before all ``_make_*()``. Each set opens with the registry's
default, its fallback for a code with no entry of its own, as
``_read_opt_unassigned()`` opens the readers of
:class:`~pcapkit.protocols.internet.ipv4.IPv4`; the rest follow the enum value
of the code or type each handles, not alphabetical order. Ruled on
:issue:`2490`.
d. **Other helpers.** Every helper that ``read()``, ``make()`` and the registries
do not reach goes last, including one that only another helper calls, such as
``_decode_text()`` in :class:`~pcapkit.protocols.application.httpv1.HTTP`.
Ruled on :issue:`2490`.

**Registry maps.** The registry maps themselves (``__proto__``, ``__option__``,
``__parameter__`` and similar) are ordered by their enum values, or alphabetically
by key where there is no enum.

**The guard.** :file:`tests/project/test_protocol_member_order_2490_unit.py` holds
every protocol class to the groups, ``_make_data()`` first, each ``_read_xxx()``
before its ``_make_xxx()``, and subgroup b, with a table of known exceptions
(:issue:`2490`).

Example
~~~~~~~

Expand Down
Loading
Loading