From dfda0f0a20a70adf165f796309450be09da975a4 Mon Sep 17 00:00:00 2001 From: Jarry Shaw Date: Thu, 29 Oct 2026 15:08:13 -0400 Subject: [PATCH] fix(protocols): revert #2432's RegistryError message to name Protocol #2432 (round 10 of #1103) changed register's RegistryError message from "...must be a Protocol subclass" to "...must be a ProtocolBase subclass" in pcapkit/protocols/protocol.py and foundation/registry/protocols.py, and updated the locked assertions in tests/protocols/test_register_class_guard_unit.py and tests/foundation/registry/test_protocols.py to match. This was a mistake. * The wording naming Protocol (not ProtocolBase) is a deliberate, ratified decision: #1016 ruled the message's reader is third-party code, who should be told to subclass Protocol -- ProtocolBase's own docstring says it is "for internal use only". The owner approved that reasoning, #2316 re-confirmed it as out of scope to change, and #2420's commit explicitly records "the error message names Protocol" as the kept half of the split between the Raises: clause (ProtocolBase) and the raised message (Protocol). #2420 also notes it already caught and corrected one prior accidental flip of this exact wording. * Reverted both raise sites and the four locked test assertions back to "Protocol subclass". * Also fixed a citation left by #2432: tests/foundation/reassembly/ test_deferred_pickle_2423_unit.py cited :issue:`2424` (the merged PR, not an issue) where it meant the underlying fix, tracked as #2423 -- matches the file's existing :issue:`2423` citation style and the changelog's own "(:issue:`2423`, :issue:`2425`, :pr:`2424`)" citation. #2432's other two fixes (a stale docstring, a cross-reference to a moved EnumField) are correct and untouched. Refs #1016, #2316, #2420 Refs #1103 Build: tests/protocols/test_register_class_guard_unit.py, tests/foundation/registry/test_protocols.py, tests/foundation/reassembly/test_deferred_pickle_2423_unit.py pass; full tests/project/ run shows no new failures (13 pre-existing failures, all in unrelated subprocess/network-dependent tests, none touching these files). --- pcapkit/foundation/registry/protocols.py | 2 +- pcapkit/protocols/protocol.py | 2 +- tests/foundation/reassembly/test_deferred_pickle_2423_unit.py | 2 +- tests/foundation/registry/test_protocols.py | 2 +- tests/protocols/test_register_class_guard_unit.py | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pcapkit/foundation/registry/protocols.py b/pcapkit/foundation/registry/protocols.py index 2c92d7f3f2..459e2d03e5 100644 --- a/pcapkit/foundation/registry/protocols.py +++ b/pcapkit/foundation/registry/protocols.py @@ -221,7 +221,7 @@ class rather than supplied by a caller, and this function is the funnel if not isinstance(protocol, type): raise RegistryError(f'protocol must be a class, not {protocol!r}') if not issubclass(protocol, ProtocolBase): - raise RegistryError(f'protocol must be a ProtocolBase subclass, not {protocol!r}') + raise RegistryError(f'protocol must be a Protocol subclass, not {protocol!r}') name = protocol.__name__.upper() incumbent = protocol_registry.get(name) diff --git a/pcapkit/protocols/protocol.py b/pcapkit/protocols/protocol.py index a96df0ec20..75b04a49f4 100644 --- a/pcapkit/protocols/protocol.py +++ b/pcapkit/protocols/protocol.py @@ -1139,7 +1139,7 @@ def _next_layer_entry(cls, code: 'Any', protocol: 'ModuleDescriptor[ProtocolBase if not isinstance(protocol, type): raise RegistryError(f'protocol must be a class, not {protocol!r}') if not issubclass(protocol, ProtocolBase): - raise RegistryError(f'protocol must be a ProtocolBase subclass, not {protocol!r}') + raise RegistryError(f'protocol must be a Protocol subclass, not {protocol!r}') return protocol @classmethod diff --git a/tests/foundation/reassembly/test_deferred_pickle_2423_unit.py b/tests/foundation/reassembly/test_deferred_pickle_2423_unit.py index 7ab929a545..1463d3b7e2 100644 --- a/tests/foundation/reassembly/test_deferred_pickle_2423_unit.py +++ b/tests/foundation/reassembly/test_deferred_pickle_2423_unit.py @@ -245,7 +245,7 @@ def test_setstate_still_accepts_the_first_revisions_flat_shape(self) -> None: """The flat ``{slot: value}`` shape the very first fix returned. Never released, but already pushed in an earlier revision of - :issue:`2424`'s fix -- accepting it costs nothing and protects anyone + :issue:`2423`'s fix -- accepting it costs nothing and protects anyone who pickled against that revision. """ diff --git a/tests/foundation/registry/test_protocols.py b/tests/foundation/registry/test_protocols.py index 830a7db3c3..c9132109ac 100644 --- a/tests/foundation/registry/test_protocols.py +++ b/tests/foundation/registry/test_protocols.py @@ -438,7 +438,7 @@ def test_register_protocol_rejects_a_non_class_with_registry_error(self) -> None ('none', None, 'must be a class'), ('descriptor argument (not unwrapped here)', ModuleDescriptor('pcapkit.protocols.misc.raw', 'Raw'), 'must be a class'), - ('wrong class', object, 'ProtocolBase subclass'), + ('wrong class', object, 'Protocol subclass'), ): with self.subTest(value=label): with self.assertRaises(RegistryError) as caught: diff --git a/tests/protocols/test_register_class_guard_unit.py b/tests/protocols/test_register_class_guard_unit.py index 853476a387..334fb469fd 100644 --- a/tests/protocols/test_register_class_guard_unit.py +++ b/tests/protocols/test_register_class_guard_unit.py @@ -82,7 +82,7 @@ def test_wrong_class_still_raises_registry_error(self) -> None: with mock.patch.dict(klass.__proto__): with self.assertRaises(RegistryError) as caught: klass.register(code, dict) # type: ignore[arg-type] - self.assertIn('ProtocolBase subclass', str(caught.exception)) + self.assertIn('Protocol subclass', str(caught.exception)) def test_descriptor_naming_a_non_class_raises_registry_error(self) -> None: from pcapkit.corekit.module import ModuleDescriptor @@ -107,7 +107,7 @@ def test_descriptor_naming_a_wrong_class_still_raises_registry_error(self) -> No with mock.patch.dict(klass.__proto__): with self.assertRaises(RegistryError) as caught: klass.register(code, descriptor) # type: ignore[arg-type] - self.assertIn('ProtocolBase subclass', str(caught.exception)) + self.assertIn('Protocol subclass', str(caught.exception)) def test_valid_class_and_descriptor_still_register(self) -> None: from pcapkit.corekit.module import ModuleDescriptor