Skip to content

Define how the parser and terminal accept strided buffers #122

In review

Description

@tony

Summary

A one-dimensional strided byte memoryview satisfies the annotated buffer interface. Three public consumers raise TypeError before parsing its two logical bytes.

Reproduction

  1. From the tagged libvt checkout, install the locked development dependencies with uv sync --frozen --python 3.14 --all-groups --all-extras. Use the checkout root as the working directory.

  2. Save the following as case.py at the checkout root.

from libvt import Terminal
from libvt.parser import Parser
from libvt.codec import explain

view = memoryview(b"A.B.")[::2]
failures = []
for name, call in (("Terminal.feed", Terminal().feed), ("Parser.feed", Parser().feed), ("explain", explain)):
    call(view.tobytes())
    try:
        call(view)
    except TypeError as error:
        failures.append(name)
        print(name, type(error).__name__, str(error))
assert not failures
  1. Run the case.
$ uv run --no-sync python case.py

Expected

Accept the logical bytes or explicitly document and validate the contiguous-only input contract consistently.

Actual

Materializing the same two bytes succeeds in the terminal, parser and explainer. Each strided input fails at a memoryview cast.

Environment

Tested versions

CPython 3.14.6 on Linux ARM64 under WSL2. The example produced the reported result against both v0.0.1a4 and the tested trunk revision.

Evidence

Observed output
Terminal.feed TypeError memoryview: casts are restricted to C-contiguous views
Parser.feed TypeError memoryview: casts are restricted to C-contiguous views
explain TypeError memoryview: casts are restricted to C-contiguous views

Proposal

Keep the zero-copy contiguous fast path and decide whether to copy other layouts or reject them with a precise boundary error.

  • Developer experience — Typed callers can determine which memoryviews they may pass without special-case knowledge of three entry points.
  • Immediate benefit — An application can reuse sliced input from a recorder or normalizer.
  • Longer-term benefit — The parser, renderer and diagnostic explainer agree on their input boundary.
  • End-user experience — Users working with buffer views get consistent output or an immediately actionable error.

References

Activity

  1. added
    bug
    p3
    on Nov 30, 2026
  2. tony commented on Dec 3, 2026

    @tony
    MemberAuthor

    Parser, terminal, recorder and explainer consume strided byte views in logical order. The forward and reversed-stride tests preserve the green CJK cell and cursor across split UTF-8 and controls, and step offsets still count consumed logical bytes. PR #186

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugp3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions