Repository navigation
refactor: self-registering packet registry + Position composition (non-breaking) - #310
Merged
Merged
Conversation
Replace the get_packet_type() if/elif chain and static TYPE_LOOKUP with a self-registering packet registry. Each concrete Packet subclass declares a packet_type ClassVar and a matches() classifier; __init_subclass__ registers it automatically and TYPE_LOOKUP is derived from the registry so the two can no longer drift out of sync. - factory() now returns Packet | UnknownPacket (was wrongly typed as type[Packet]); _type deserialization uses a registry-backed name lookup instead of globals() - ThirdPartyPacket.subpacket is typed Optional[Packet] and from_dict() re-dispatches the raw sub-packet through factory() so dataclasses-json doesn't pre-build a lossy base Packet - beacon fallback (unrecognized format + latitude) preserved in get_packet_type(); dead factory branches removed Behavior is unchanged: full test suite (775) passes.
Replace the flat GPS fields on GPSPacket and its subclasses with a
composed Position value object (has-a instead of is-a), collapsing the
Packet -> GPSPacket -> {Beacon, MicE, Telemetry, Object, Weather}
data spine. Position owns the coordinates, symbol, movement/PHG data
and the conversion/formatting logic (zulu time, DDM, human_info).
- GPSPacket holds position: Optional[Position]; subclass defaults
preserved via _position_default() (ObjectPacket 'r', WeatherPacket '_')
- to_dict()/from_dict() flatten/unflatten so the on-disk JSON format
is unchanged; verified via objectstore save/load round-trip
- GPSPacket inherits DataClassJsonMixin directly because the
@dataclass_json decorator overwrites to_dict()/from_dict() and would
clobber the flattening overrides
- constructor is breaking: position=Position(...) instead of
latitude=.../longitude=...; updated tx.py, log.py and all tests
Full test suite (775) passes; ruff format + lint clean.
Add an [Unreleased] section to ChangeLog.md covering the self-registering packet registry and the Position composition refactor, and regenerate docs/source/changelog.md via prepare_changelog.py. Also teach prepare_changelog.py to normalize the [Unreleased] heading level so the Sphinx copy stays consistent with version headings.
hemna
force-pushed
the
experimental/packet-registry
branch
from
September 24, 2026 14:21
0564bad to
03a5fd0
Compare
hemna
added a commit
that referenced
this pull request
Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two refactors to
aprsd/packets/core.pyon the experimental branch, inspired by the "type object" design pattern discussion:72541bf)f30f764) — with a backward-compatibility shim so external plugins/extensions need no changesBehavior is unchanged for existing callers: full test suite (782) passes, ruff format/lint clean, and all plugins/extensions in the ecosystem run their original, unmodified code (verified against all 26 plugin repos).
1. Self-registering packet registry
Replaces the
get_packet_type()if/elif chain and the staticTYPE_LOOKUPdict with a registry that packet classes register into automatically via__init_subclass__. Each concrete packet class declares apacket_type: ClassVar[str]and amatches(raw)classifier;TYPE_LOOKUPis derived from the registry so the two can no longer drift out of sync.factory()now returnsPacket | UnknownPacket(was wrongly annotated-> type[Packet]);_typedeserialization uses a registry-backed name lookup instead ofglobals()ThirdPartyPacket.subpacketis typedOptional[Packet]andfrom_dict()re-dispatches the raw sub-packet throughfactory()so dataclasses-json doesn't pre-build a lossy basePacketget_packet_type(); deadfactory()branches removedAdding a new packet type is now a single-class change — no central dispatch table to edit.
2. Position value object composition (non-breaking)
Collapses the
Packet → GPSPacket → {Beacon, MicE, Telemetry, Object, Weather}data spine. All position data (lat/lon/altitude/symbol/comment/course/speed/PHG/DAO) and its conversion/formatting logic (zulu time, DDM,human_info) now lives in a frozenPositionvalue object thatGPSPacketcomposes (has-ainstead ofis-a).Backward compatibility — external plugins/extensions keep working unmodified:
position=Position(...)(canonical) and the legacy flat kwargs (latitude=,longitude=,symbol=,comment=,speed=, ...). The legacy form emits aDeprecationWarningand is scheduled for removal in a future release.packet.latitude,packet.comment, ...) keep working via read-only delegating properties.ObjectPacket→r,WeatherPacket→_) when using the legacy flat form.to_dict()/from_dict()flatten/unflatten the nested position, so persisted object-store files keep loading.TODO(remove)in the code (target: next major release) so the deprecated path doesn't linger.GPSPacketinheritsDataClassJsonMixindirectly because the@dataclass_jsondecorator unconditionally overwritesto_dict()/from_dict()and would clobber the flattening overrides.Docs / changelog
[Unreleased]section toChangeLog.mdand regenerateddocs/source/changelog.mddocs/prepare_changelog.pynow also normalizes the[Unreleased]heading level so the Sphinx copy stays consistent with version headingsTesting
pytest tests→ 782 passedruff format+ruff check→ clean~/devel/mine/hamradio/aprsd-plugins: the 6 that use GPS packet constructors/reads pass with their original, unmodified code against this branch (repeat 60/60, webchat 71/73 — the 2 remaining failures are a pre-existing config issue that reproduces at the base commit without this PR, gps/weewx/rich-cli/digipi 1/1 each)