Repository navigation
Conversation
Use native Python types instead and wrap them in `Annotated` to provide needed metadata. For example `U8` is now a `TypeAlias` of `Annotated[int, metadata]`. Resulting UX is similar as before for protocol definition, but we use native `int` or `float` at runtime. This also fixes an annoyance with type checkers which didn't accept literals like `3` as `U8`.
blazraST
requested review from
moucha19-st
and
a balanced review from Copilot
November 26, 2026 17:10
There was a problem hiding this comment.
🟡 Changes recommended
Enum definitions accept values outside their backing type’s range, causing serialization failures; validate every member’s signedness and width before registering the class.
1 open issue
What changed in this PR
This PR replaces custom Python numeric classes with native int and float types carrying wire-format metadata through Annotated, improving compatibility with type checkers and numeric literals.
Changes:
- Updates serialization and code generation to resolve numeric metadata.
- Migrates enum definitions to
IntEnumwith explicit backing-type decorators. - Updates documentation and renames bit-precise integer fixtures across Python, C, and C#.
| File | Description |
|---|---|
test/test_compost.py |
Updates bit-precise integer notification tests. |
test/protocol_impl.c |
Renames the matching C notification handler and serializer call. |
test/protocol_def.py |
Migrates enums and renames bit-precise integer fixtures. |
test/mock/main.c |
Updates mock notification types and serializer call. |
example_protocol_def.py |
Demonstrates the new enum declaration syntax. |
docs/user_guide/generating_code.md |
Updates enum naming examples to use IntEnum. |
docs/user_guide/datatypes/index.md |
Clarifies byte-aligned versus bit-precise scalars. |
docs/user_guide/datatypes/enums.md |
Documents explicit enum backing types. |
csharp/tests/CompostRpc.IntegrationTests/TestProtocol/TestProtocolTypes.cs |
Renames bit-precise integer fixture classes. |
csharp/tests/CompostRpc.IntegrationTests/TestProtocol/TestProtocol.Implementation.cs |
Updates notification fixture construction. |
csharp/tests/CompostRpc.IntegrationTests/TestProtocol/TestProtocol.cs |
Renames the notification event and updates its description. |
csharp/tests/CompostRpc.IntegrationTests/NotificationTestsBase.cs |
Updates notification tests to use renamed fixtures. |
compost_rpc/compost_rpc.py |
Introduces annotated numeric aliases, metadata-based serialization and generation, and immutable memory sizes. |
Review effort: Balanced
|
|
||
| def __copy__(self): | ||
| return self | ||
| cls.backing_type = backing_type |
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.

Use native Python types instead and wrap them in
Annotatedto provide needed metadata. For exampleU8is now aTypeAliasofAnnotated[int, metadata]. Resulting UX is similar as before for protocol definition, but we use nativeintorfloatat runtime.This also fixes an annoyance with type checkers which didn't accept literals like
3asU8.