Skip to content

[DEV] (2.5.0-rc) Updates to resolving the root-context #35

Merged
MatrixEditor merged 2 commits into
dev/2.5.0-rcfrom
dev/2.5.0-rc_context-root
Jun 27, 2025
Merged

[DEV] (2.5.0-rc) Updates to resolving the root-context #35
MatrixEditor merged 2 commits into
dev/2.5.0-rcfrom
dev/2.5.0-rc_context-root

Conversation

@MatrixEditor

Copy link
Copy Markdown
Owner

Changes

  • 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.
  • Removed type hints in exception.py

---

+ New context attribute: '_root' can be set to point to the root context instance
+ Removed type hints in exception.py
@MatrixEditor MatrixEditor merged commit d958910 into dev/2.5.0-rc Jun 27, 2025
@MatrixEditor MatrixEditor deleted the dev/2.5.0-rc_context-root branch June 27, 2025 14:04
MatrixEditor added a commit that referenced this pull request Jun 29, 2025
---

## 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
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.

1 participant