Skip to content

[DEV] (2.5.0) Stub files and various improvements#32

Merged
MatrixEditor merged 46 commits into
masterfrom
dev/2.5.0-rc
Jun 29, 2025
Merged

[DEV] (2.5.0) Stub files and various improvements#32
MatrixEditor merged 46 commits into
masterfrom
dev/2.5.0-rc

Conversation

@MatrixEditor

@MatrixEditor MatrixEditor commented Jun 25, 2025

Copy link
Copy Markdown
Owner

Linked to #31. This branch will store all modifications, updates and improvements made to the project. For a list of changes, refer to #31.

Closes #31
Closes #34
Closes #35

---

abc.py:
+ removed unused '_ContextPathStr'
+ Removed unnecessary 'abstractmethod' definitions
+ '_Action' was renamed to '_ActionLike'
+ removed '_EnumLike'
+ '_Switch' was renamed to '_SwitchLike'
+ Added two new protocols: '_SupportsBits' and '_ContainsBits'
+ The following constants and methods were moved into shared.py: STRUCT_FIELD -> ATTR_STRUCT, hasstruct, getstruct and typeof
---

_common.py:
+ Removed any existing typing information
+ unpack_seq and pack_seq now return or use a collection instead of a list
---

byteorder.py:
+ moved 'BYTEORDER_FIELD' to shared.py as ATTR_BYTEORDER
---

+ shortcuts now include typeof, to_struct, hasstruct, getstruct and sizeof
---

+ Removed unnecessary type hints in python code
+ Fixed an issue with unions declared using the Sequence class
---

_struct.py:
+ Removed type hints in original python file
+ Sizeof() now raises a TypeError when the target object does not implement the __size__ protocol
---

_bitfield.py:
+ Moved attribute constants to caterpillar.shared.
+ Removed getformat().
+ Removed type hints from the original file.
+ Fixed issue where field options defined in BitField were not populated when creating fields.

_base.py:
+ Fixed issue where field options defined in Sequence were not populated when creating fields.
+ Added private methods to stubs.
---

_template.py:
+ Moved template attribute constant to shared.py
+ removed all type hints

+ Updated imports in _bitfield, _struct and _base
---

_base.py:
+ Removed all type hints
---

fields.common.py:
+ Transformer: removed __fmt__ method

fields.compression.py:
+ Updated public compression methods to use lazy imports
---

abc.py:
+ Removed __type__() requirement from '_StructLIke' as described in the docs
+ Added new protocol: _SupportsType
Merge pull request #30 from MatrixEditor/dev/2.5.0-rc_stubs
---

abc.py:
+ _ActionLike was removed and splitted into two separate protocols:_SupportsActionUnpack and _SupportsActionPack
---

+ BitField was renamed to Bitfield
+ Each Bitfield now stores a list of groups, which either represent a field or a list of entries
+ bitfield_example was updated
---

+ New option: B_NO_AUTO_BOOL to disable automatically assigning fields with one bit width a boolean factory
---

+ Updated imports in __init__
+ Added two new value factories: CharFactory and EnumFactory
+ Bitfields now corrently populate documentation types if S_REPLACE_TYPES is active
Merge pull request #34 from MatrixEditor/dev/2.5.0-rc_bitfield
---

+ New context attribute: '_root' can be set to point to the root context instance
+ Removed type hints in exception.py
Merge pull request #35 from MatrixEditor/dev/2.5.0-rc_context-root
---

+ Split up the datamodel reference into multiple files
+ New custom CSS for tables
---

+ Add v2.5.0 changelog to docs
+ Split up model library docs into several files
+ All sections are now numbered
+ Remove caterpillar.abc library docs
+ Add caterpillar.shared library docs
---

+ Update Changelog title
+ Create CHANGELOG.md
---

+ Remove annotations from shared.py
+ Change warning for conditional context to be displayed only when entering the condition with __enter__
+ Update pack and unpack examples in doc-comments
---

+ Update README text
+ Change bitfield example to use extended syntax
Merge pull request #36 from MatrixEditor/dev/2.5.0-rc_docs
Merge pull request #37 from MatrixEditor/dev/2.5.0-rc_cleanup
@MatrixEditor MatrixEditor marked this pull request as ready for review June 29, 2025 10:09
---

+ Update README example
---

## Changes made

The code of all modules were refactored to include as little type hints as possible now. All typing related information should be taken from `.pyi` files.

##### `caterpillar.abc`

- Removed `_Action` and split into two separate Protocols `_ActionLike` := `_SupportsActionUnpack` | `_SupportsActionPack`
- Renamed `_Switch` to `_SwitchLike`
- Removed `_EnumLike`
- Added two new protocols: '_SupportsBits' and '_ContainsBits'
- The following attributes and methods were moved into [caterpillar.shared](#caterpillarshared): `STRUCT_FIELD` -> `ATTR_STRUCT`, `hasstruct`, `getstruct` and `typeof`
-  Removed unused '_ContextPathStr'
- Removed `__type__()` requirement from '_StructLike'
- Added new protocol: `_SupportsType`

##### `caterpillar.byteorder`

- Moved 'BYTEORDER_FIELD' to [caterpillar.shared](#caterpillarshared) as `ATTR_BYTEORDER`

##### `caterpillar.shortcuts`

- Shortcuts now include `typeof`, `to_struct`, `hasstruct`, `getstruct` and `sizeof`

##### `caterpillar.shared`

- New constants moved from other modules: `ATTR_BYTEORDER`, `ATTR_TYPE`, `ATTR_BITS`, `ATTR_SIGNED`, `ATTR_TEMPLATE`

##### `caterpillar.context`

- New context attribute: '_root' can be set to point to the root context instance. Internally, instead of a for-loop that iterates through parent context instances, a simple self.get(...) call is made. (see #35)

##### `caterpillar.model._base`

- Fixed an issue when parsing union objects with an unbound stream object
- Fixed an issue where field options defined in Sequences were not populated when creating fields.

##### `caterpillar.model._struct`

- `sizeof` now checks if the provided object implements the `_SupportsSize` protocol

##### `caterpillar.model._bitfield`

- **Completely reworked the bitfield mechanism to make it even more powerful. For details refer to #34.**
- Fixed an issue where field options defined in BitFields were not populated when creating fields.
- Moved `BITS_ATTR` and `SIGNED_ATTR` into [caterpillar.shared](#caterpillarshared)
- Removed unused `getformat` function

##### `caterpillar.fields.common`

- `Transformer`: removed `__fmt__` method

##### `caterpillar.fields.compression`

- Updated public compression methods to use lazy imports

#### Documentation

- Updated library documentation to reflect changes made to function signatures
- Updated the reference to explicitly state the Protocols defined in `caterpillar.abc`
- Created a change log to reflect changes made up to v2.5.0

## Associated Issues and Pull Requests

- #30: Stub files for Caterpillar allowing to use generics and more detailed return types
- #27: Python3.14 does NOT break this project. However, some features (with-statements) can't be used
- #34: Introducing a new Bitfield concept to make it even more flexible
- #35: Optimized resolving the root context instance
- #37: Various small fixes related to the documentation
- #24: Bitfield docs
- #33: General documentation updates
@MatrixEditor MatrixEditor merged commit 06dfa47 into master Jun 29, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DEV] (2.5.0) Stub files and various improvements

1 participant