Skip to content

Read-only properties - #470

Merged
joente merged 7 commits into
mainfrom
readonly
Oct 30, 2026
Merged

joente merged 7 commits into
mainfrom
readonly

Conversation

@joente

@joente joente commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Description

This pull request implements the option to define properties as read-only.

For example:

set_type('T', {
  name: 'str',
  key: 'bytes(ro)',
  created: 'datetime(ro)',
});

When creating an instance if type T, we can only set key and created on initialization time. After the instance is created, it is no longer possible to change the values.

If really required, mod_type(..) can be used to remove the read-only marker, then changes can be made and optionally the read-only marker can be re-applied

t = T{
  name: 'test',
  key: bytes(base64_encode(randstr(12))),
};
t.name = 'test2';  // This is fine!
// t.key = bytes(); // OperationError: mismatch in type `T`; property `key` is read-only
// t.created = datetime(); // OperationError: mismatch in type `T`; property `created` is read-only

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Test advanced (added read-only tests, import/export structure tests, rename type tests)
  • Test enum (added rename enum tests)
  • Test imprt (test raw import/export with data)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • New and existing unit tests pass locally with my changes

@joente joente self-assigned this Oct 29, 2026
@joente
joente merged commit 3819e38 into main Oct 30, 2026
1 check passed
@joente
joente deleted the readonly branch October 30, 2026 10:41
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.

1 participant