[DEV] v2.8.0: Extended syntax & typing fixes#55
Merged
Conversation
--- + Merge byteorder stubs into byteorder.py + Merge abc.py
--- + Fix abc.py type definitions
--- + Add _ContextFactoryLike protocol
--- + TypeVar is not imported from typing_extensions to support the default argument + Add _SwitchOptionsT + Make _ArchLike, _EndianLike and _OptionLike '@runtime_checkable'
--- + getstruct(): update annotations to support @struct defined types + typeof(): now supports NotImplementedError and NotImplemented as return type
--- + ContextPath: dropped support for the call action
--- + fix __getitem__ return type annotation + fix switch annotation in __rshift__ + Field.get_name() now always returns a string
--- + Merge compression,py stubs
--- + Merge conditional.py stubs
--- + Merge digest.py stubs
--- + Rename ssize and size in caterpillar.fields exports + Sequence: add support for Annotated values + Merge model._base annotations
--- + Merge template.py as well
--- + shortcuts: New export "f" which aliases the Annotated function for extended syntax + new module: types - defines default types that can be used as annotations within struct definitions
--- + Update examples and remove type errors + options.get_flags() always returns list + add missing global exports + Add protocol compliance tests + Add more tests for Flag class
--- NEW: + O_DEFAULT_ENDIAN as a global option to set a global default byteorder + O_DEFAULT_ARCH same concept for arch-like objects + Add new 'strict' option to Enum struct + Add 'order' and 'arch' options to pack() and unpack(), which temporarily change the global endianess or arch (compatible with Dynamic byteorder) + Add extra options to extended syntax allowing OptionLike, EndianLike and ArchLike + Add ATTR_PACK and ATTR_UNPACK to caterpillar.shared CHANGES: + Update common structs and bitfield implementation to support new global byteorder option + Fix IntFlag issure with Enum structs (#56) + Bitfield, Struct and Sequence now respect fields with already configured byteorder
--- + Add new byteorder tests + Add enum tests for Python's IntFlag
---- + Export 'f' shortcut in caterpillar.py
--- CHANGES: + Add Padding class including custom fill pattern and parsing checks + Add padding tests + move __set_byteorder__ into ByteOrderMixin + Prefixed struct now does not require as_field=True when calling pack() or unpack() + Add custom type: balign_t for special boundary alignment in bitfields
--- + Update README + Fix ConditionalContext to support Annotated types
--- + Update README to include default syntax as well + Update benchmark script to use new extended syntax + caterpillar.shared: renamed identity -> constval + Add missing AsLengthRef to exports + sizeof() now always returns an integer NEW: + Add new parentctx context path + Add new struct-mixin example + Add new generic timestatmp class + Add new concept: invisiable class attributes for type checkers + Add new struct-mixin class to help type checkers
--- + Add timestamp_t for unix timestamps
--- + Context and ContextPath now include type checker hints for special context variables + Renamed size and ssize to psize and pssize
--- + Cleanup _C.pyi stubs file
--- + Add _C protocol conformance tests
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.
This pull request tracks the status while transitioning to the v2.8.0 release
As mentioned in #53, having a type-checker compliant class definition would increase the usability of this library, changes made here introduce a new syntax, named "extended syntax". It allows specifying fields alongside their Python type without breaking the core concept of caterpillar.
The newly introduced type aliases apply a specific naming scheme and always end with
_t, so they can be distinguished from normal struct types.TBD
Additions
Invisiblefield specifier that can be used to "hide" struct fields in the constructor (when using a type checker)struct_factory.mixinandbitfield_factory.mixinboth provide default function wrappers for packing and unpacking data as well as typing fixes for operating on types directly.order=in pack() or unpack())TimestatmpclassOther changes
paddingstruct now has its own dedicated classEnumstructs (IntFlag support & global default endianess #56)Fixes #54