Skip to content

Decode pkl-binary Bytes, and tolerate future extra slots - #16

Open
JahJajaka wants to merge 1 commit into
jw-y:mainfrom
JahJajaka:sync/pkl-0.30.0-bytes-decoding
Open

Decode pkl-binary Bytes, and tolerate future extra slots#16
JahJajaka wants to merge 1 commit into
jw-y:mainfrom
JahJajaka:sync/pkl-0.30.0-bytes-decoding

Conversation

@JahJajaka

Copy link
Copy Markdown

apple/pkl 0.30.0 formalizes a forward-compatibility contract in its wire format docs, and Pkl 0.29 introduced a Bytes value type that pkl-python never learned to decode. Concretely, comparing binary-encoding.adoc between the 0.29.1 and 0.30.0 tags:

  • Bytes (type code 0x0F) had no registered decoder in pkl.parser.Parser, so any Bytes-valued property silently became {"type": "Unknown", "value": obj} instead of actual bytes.
  • The updated spec states: "Additional slots may be added to types in future Pkl releases. Decoders must be designed to defensively discard values beyond the number of known slots for a type." Several decoders used fixed-arity tuple unpacking (_, value, unit = obj), which would raise ValueError: too many values to unpack the moment a future Pkl release appends a slot to Typed/Dynamic, Duration, Property, Entry, or Element.

This PR:

  • Adds Bytes decoding, mapping it to native Python bytes (documented in the README type-mapping table alongside Regex, Pair, etc.).
  • Switches the affected decoders to positional indexing so trailing slots are ignored rather than crashing.
  • Adds unit tests (tests/test_parser_binary_encoding.py) covering both, exercising Parser.handle_type directly against hand-built wire-format arrays so they don't need a running pkl binary.
  • Bumps the pinned VERSION in the dev-only scripts/download_binary.py from 0.25.2 to 0.30.0 (verified the referenced asset filenames still exist on that release).

No behavior change for existing well-formed payloads — this only adds a previously-missing decode path and makes existing decoders more permissive of trailing data.

Reviewed the apple/pkl 0.30.0 release diff (0.29.1...0.30.0) against
docs/modules/bindings-specification/pages/binary-encoding.adoc:

- `Bytes` (type code 0x0F, introduced in Pkl 0.29 and used more heavily
  since 0.30, e.g. YAML binary scalars and the new pkl-binary renderer)
  had no decoder registered in pkl.parser.Parser, so any Bytes-valued
  property silently decoded to `{"type": "Unknown", "value": obj}`
  instead of the actual bytes.
- 0.30.0 formalizes a forward-compatibility contract: "Additional slots
  may be added to types in future Pkl releases. Decoders must be
  designed to defensively discard values beyond the number of known
  slots for a type". Several decoders used fixed-arity tuple unpacking
  (`_, value, unit = obj`), which raises "too many values to unpack" the
  moment a future release appends a slot to Typed/Dynamic, Duration,
  Property, Entry, or Element. Switched these to positional indexing so
  extra trailing slots are ignored per spec.

Also bumps scripts/download_binary.py's pinned VERSION to 0.30.0
(verified all 5 referenced asset filenames still exist on that release)
and documents Bytes -> bytes in the README type-mapping table.

Out of scope, left for follow-up: Class/TypeAlias decoding was already
a pre-existing no-op unrelated to 0.30.0; the 0.26 Http/proxy evaluator
option and 0.30's new pkl-binary in-language renderer are unrelated
protocol/stdlib additions that don't affect existing wire decoding.

Signed-off-by: JahJajaka <r2e4d6@gmail.com>
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.

1 participant