Repository navigation
FileParser.from_bytes falls back to from_fileobj - #311
Merged
Merged
Conversation
) The default `FileParser.from_bytes` now wraps the bytes in `io.BytesIO` and calls `from_fileobj` when the class implements `from_fileobj` itself, so a binary format that only reads a header from a stream can be loaded from bytes. Pass-through implementations (the `FileParser` default and the `FormatDispatcher` forwarder) are marked and skipped when walking the MRO, and a re-entry guard catches unmarked forwarders, so a parser with neither entry point still raises `ParserNotImplementedError` instead of recursing. `Hdf5Parser.from_bytes` was identical to the new default and is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VmK1jLTwd2hMkvYnMWEyYw
balbasty
pushed a commit
that referenced
this pull request
Oct 6, 2026
…e wiring Brings the operation objects (`derive(operation)`), the hidden `format` of the format classes, and origin/main with #311. The images and the Zarr pyramid move to `derive(operation)` in the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VmK1jLTwd2hMkvYnMWEyYw
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.
Part of #297.
Problem.
FileParser.from_fileobjreads the whole stream and hands it tofrom_bytes, butFileParser.from_bytesraisesParserNotImplementedError. So a binary format that implements onlyfrom_fileobj, because it reads just a header from a stream, couldn't be loaded from bytes.Hdf5Parser, and the metadata parsers in #310, each worked around this with their ownfrom_bytes = from_fileobj(BytesIO(...)).Change.
from_fileobj,FileParser.from_bytesnow wraps the bytes inio.BytesIOand calls it.ParserNotImplementedError, without recursing:super(): theFileParserdefault andFormatDispatcher's forwarder, both tagged by a small marker decorator.from_bytesfor the same class, for forwarders that aren't tagged (e.g. FNIRT, NIfTI fields, arrays).TextFileParser.from_bytesis unchanged (it still decodes to text).Hdf5Parser.from_bytesis removed; it was identical to the new default.Tests. Seven new tests in
tests/test_io_parsers.py:from_content, and from a subclass;from_fileobjraises instead of recursing;FormatDispatcherisn't mistaken for an override;Full suite: 4978 passed. Ruff and codespell are clean.
Once this merges, #310 drops its
MetadataParser.from_bytesoverride.🤖 Generated with Claude Code
https://claude.ai/code/session_01VmK1jLTwd2hMkvYnMWEyYw
Generated by Claude Code