Skip to content

Array assignment#18

Merged
lacraig2 merged 2 commits intomainfrom
arrayasign
Mar 13, 2026
Merged

Array assignment#18
lacraig2 merged 2 commits intomainfrom
arrayasign

Conversation

@lacraig2
Copy link
Contributor

This pull request enhances the assignment capabilities for struct array fields in the dwarffi library, making array assignment more flexible and robust. The changes introduce support for assigning lists, tuples, and BoundArrayView objects directly to array fields, improve error handling, and add comprehensive tests to cover these new behaviors.

Array assignment enhancements:

  • The __setattr__ method in src/dwarffi/instances.py now supports direct assignment of Python lists, tuples, and BoundArrayView objects to array fields, in addition to the previous support for strings and bytes. This allows for element-wise assignment and fast zero-copy memory slices for compatible types.
  • Error handling for invalid assignment types has been improved: assigning an unsupported type (such as an int) to an array field now raises a TypeError with a clear message, instead of a NotImplementedError.

Testing improvements:

  • The relevant test in tests/test_struct_array_assignment.py has been updated to expect a TypeError (with the new error message) for invalid array assignments.
  • A new comprehensive test, test_array_advanced_assignment, has been added in tests/test_struct_array_assignment_advanced.py to verify assignment of lists, tuples, and BoundArrayView objects to array fields, as well as to check correct error handling for size and type mismatches.

@lacraig2 lacraig2 merged commit 78edd1c into main Mar 13, 2026
3 checks passed
@lacraig2 lacraig2 deleted the arrayasign branch March 13, 2026 13:22
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