Skip to content

fix(foundation): registrar error messages and type hints name the public class, not the Base the guard checks #1016

Description

@JarryShaw

Extractor's three registrar methods check against the *Base classes but name the public class in their error message, so a caller who trips the guard is told the wrong type is required.

In pcapkit/foundation/extraction.py:

check message
:452 issubclass(engine, EngineBase) :453 "engine must be an Engine subclass"
:491 issubclass(reassembly, ReassemblyBase) :492 "reassembly must be a Reassembly subclass"
:530 issubclass(traceflow, TraceFlowBase) :531 "traceflow must be a TraceFlow subclass"

The accepted type is wider than the message says: Engine, Reassembly and TraceFlow are each a strict subclass of their base, and the shipped classes derive from the base directly. So a class that subclasses EngineBase is accepted while the message implies it should not be, and a reader who hits the error is sent to fix something that was never wrong.

Two related narrowings in the same area:

  • register_extractor_engine and its siblings are annotated Type[Engine], narrower than the runtime check, so a legitimate EngineBase subclass is a type error at a call site that works at runtime.
  • register_protocol checks issubclass(protocol, ProtocolBase); its message and annotation should be checked for the same mismatch.

Found while sweeping docstrings for #719. The prose side is corrected in #1015, which deliberately left these alone because the messages and annotations are code, not documentation. #513 and #514 are the same conflation approached from the caller's side.

The fix is a judgement call rather than mechanical: either widen the messages and annotations to the *Base classes, matching the guard, or narrow the guards to the public classes, which would be a behaviour change and needs a ruling.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixPull requests that fix a defect (fix: subject prefix)

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions