Skip to content

Propagate stream finalization attribute lookup errors - #383

Open
FFspiky wants to merge 1 commit into
indygreg:mainfrom
FFspiky:fix-stream-finalization-lookup-errors
Open

FFspiky wants to merge 1 commit into
indygreg:mainfrom
FFspiky:fix-stream-finalization-lookup-errors

Conversation

@FFspiky

@FFspiky FFspiky commented Nov 16, 2026

Copy link
Copy Markdown

Use PyObject_HasAttrStringWithError for the six exercised stream finalization probes: writer flush/close and reader close, for compression and decompression. Missing optional methods remain allowed, while MemoryError and KeyboardInterrupt during lookup reach the caller.

Partially addresses #299: only these six stream flush/close probes. Constructor/copy_stream validation, fileno, and buffer-protocol errors are outside this patch.

Regression coverage: MemoryError and KeyboardInterrupt from lookup at all six sites; absent optional methods; close remains idempotent and retains existing closed-state semantics. Unchanged CFFI passes the same cases.

Validation on macOS 26.2 arm64 / CPython 3.12.14:

  • ZSTD_WARNINGS_AS_ERRORS=1 python setup.py build_ext --inplace builds the C and CFFI extensions.
  • ZSTD_SLOW_TESTS=1 python -m pytest -q -n 4: 304 passed.
  • PYTHON_ZSTANDARD_IMPORT_POLICY=cffi ZSTD_SLOW_TESTS=1 python -m pytest -q -n 4: 278 passed, 26 skipped.
  • Affected stream test modules: 89 passed on each backend. The new failure cases fail on the C baseline and pass after the fix; unchanged CFFI passes the same regressions.
  • ruff check ., mypy tests/*.py zstandard/*.py, changed-file ruff format --check, and git diff --check pass.
  • Full ruff format --check . reports only an existing setup.py indentation issue, reproduced on the untouched base.

Both runs enabled ZSTD_SLOW_TESTS=1 with the default Hypothesis profile (100 examples), rather than the CI profile (1000 examples).

An additional backend comparison found an existing difference: CFFI still looks up close when closefd=False, so lookup can raise there even though the C backend skips it. This patch preserves the C guard and leaves that separate CFFI behavior unchanged.

Linux/Windows, other Python versions, PyPy, and the experimental Rust backend were not run locally.

AI disclosure: Code, tests, and this description were generated with OpenAI Codex and validated with automated local checks. This does not claim human review.

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