[DEV] (2.5.0-rc) Updates to resolving the root-context #35
Merged
Conversation
--- + New context attribute: '_root' can be set to point to the root context instance + Removed type hints in exception.py
This was referenced Jun 27, 2025
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
self.get(...)call is made.