Skip to content

Conversation

@Intuity
Copy link
Owner

@Intuity Intuity commented Jul 25, 2025

A number of small improvements:

  • Flags unused or invalid constant overrides when parsing packtype grammar
  • Constant expressions can be optionally attached as _PT_EXPRESSION if keep_expression=True when using packtype grammar (utils.constant.get_expression() can be used to retrieve this)
  • Addition of __float__ and __index__ methods to NumericPrimitive to reduce the need for explicit int(...) casts in many places

@Intuity Intuity requested a review from Copilot July 25, 2025 08:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_EXPRESSION attribute when keep_expression=True
  • Adds __float__ and __index__ methods to NumericPrimitive to 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

@Intuity Intuity merged commit 8ccfab0 into main Jul 25, 2025
6 checks passed
@Intuity Intuity deleted the intuity/fixes branch July 25, 2025 08:52
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.

2 participants