diff --git a/CHANGELOG.md b/CHANGELOG.md index d1d66c1..5cf04b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,12 @@ ## [Unreleased] **Fixes:** - Made `SubconParsedType` and `SubconBuildTypes` invariant. +- Fixed return type of `Construct._build()`: `int` was wrong and worked only in specific cases. **Changes:** - Removed some code paths for Python versions below 3.8. + ## [0.8.1] - 2026-07-23 **New features:** - Added `Subconstruct`, `SymmetricAdapter`, `Tunnel` and `Validator` to `construct_typed` as subscriptable types. diff --git a/construct-stubs/core.pyi b/construct-stubs/core.pyi index 64a4b0a..b039581 100644 --- a/construct-stubs/core.pyi +++ b/construct-stubs/core.pyi @@ -160,9 +160,11 @@ class Construct(t.Generic[ParsedType, BuildTypes]): def _parsereport( self, stream: StreamType, context: Context, path: PathType ) -> ParsedType: ... + # In most implementations, `_build()` actually returns `ParsedType`, in some others it + # returns `BuildTypes` or something else entirely. `t.Any` seems a good compromise. def _build( self, obj: BuildTypes, stream: StreamType, context: Context, path: PathType - ) -> int: ... + ) -> t.Any: ... def _sizeof(self, context: Context, path: PathType) -> int: ... @t.type_check_only diff --git a/tests/test_core.py b/tests/test_core.py index aad3516..6e6b33b 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1781,6 +1781,16 @@ def __init__( hashfunc: t.Callable[[bytes], BuildTypes], bytesfunc: t.Callable[[Context], bytes], ) -> None: ... + + def _parse(self, stream: t.IO[bytes], context: Context, path: str) -> ParsedType: + ... + + def _build(self, obj: BuildTypes, stream: t.IO[bytes], context: Context, path: str) -> t.Any: + ... + + def _sizeof(self, context: Context, path: str) -> int: + ... + else: import binascii