Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional variables #53

Closed
lojack5 opened this issue Oct 3, 2024 · 0 comments · Fixed by #57
Closed

Conditional variables #53

lojack5 opened this issue Oct 3, 2024 · 0 comments · Fixed by #57
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@lojack5
Copy link
Owner

lojack5 commented Oct 3, 2024

I want to add an annotation that allows for unpacking/packing a variable only when a condition is met.

Initial design thoughts

  • Indicated inside of Annotated[...].
  • User supplied callable, taking the Structured object/proxy object to be packed/unpacked and returning a Truthy value. If True, pack/unpack as normal, if False, behave as if the class never had the attribute in its definition, and fill in that attribute with some (user specified?) default value.

Maybe something like:

class MyStruct(Structured):
  version: uint32
  field1: int8
  field2: Annotated[int8, Condition(lambda o: o.version >= 2, default=-1)]
@lojack5 lojack5 added the enhancement New feature or request label Oct 3, 2024
@lojack5 lojack5 self-assigned this Oct 3, 2024
@lojack5 lojack5 added this to the 3.1.0 Release milestone Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant