Skip to content

Get rid of custom Compost types - #18

Draft
blazraST wants to merge 1 commit into
mainfrom
annotated
Draft

blazraST wants to merge 1 commit into
mainfrom
annotated

Conversation

@blazraST

Copy link
Copy Markdown
Collaborator

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.

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
blazraST requested review from moucha19-st and a balanced review from Copilot November 26, 2026 17:10
@blazraST blazraST self-assigned this Nov 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 IntEnum with 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants