Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds several small improvements to the packtype library including better constant override validation, optional expression preservation for constants, and enhanced numeric primitive methods.
- Adds validation to flag unused or invalid constant overrides when parsing packtype grammar
- Enables optional preservation of constant expressions as
_PT_EXPRESSIONattribute whenkeep_expression=True - Adds
__float__and__index__methods toNumericPrimitiveto reduce explicit casting needs
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packtype/grammar/grammar.py | Adds validation for constant overrides and expression preservation logic |
| packtype/types/constant.py | Adds _PT_EXPRESSION attribute to store parsed expressions |
| packtype/types/numeric.py | Adds __index__ method for numeric primitives |
| packtype/types/primitive.py | Adds __float__ method for primitive types |
| packtype/utils/constant.py | New utility module for constant-related operations |
| packtype/common/expression.py | Refactors expression classes with improved naming and documentation |
| tests/ | Various test files covering new functionality |
| examples/structs/spec.pt | Updates example to use constants for field widths |
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.
A number of small improvements:
_PT_EXPRESSIONifkeep_expression=Truewhen using packtype grammar (utils.constant.get_expression()can be used to retrieve this)__float__and__index__methods toNumericPrimitiveto reduce the need for explicitint(...)casts in many places