refactor(api)!: one way to ask what a file is - #835
Merged
Conversation
Twelve entry points answered the question. Four were the free functions; four more were DecodedFile statics the free functions forwarded to, so the same call had two spellings and the bindings picked different ones - apple went through the statics, jni through the free function. The bodies move to the free functions and the statics go. The other four were DocumentFile::type and ::meta, which decoded the entire file to read a single field and threw NoDocumentFile for anything that was not a document. open(...).file_type() and .file_meta() say the same thing without the narrowing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016hxDa2rev11eLUEJZJ5nmz
detect() reached for the statics rather than the free functions, and nothing local builds wasm, so it went unnoticed until a syntax check against the emscripten toolchain. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016hxDa2rev11eLUEJZJ5nmz
andiwand
force-pushed
the
refactor/one-way-to-detect
branch
from
September 6, 2026 13:36
3ba5f19 to
0e2a00c
Compare
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.
🤖 Generated with Claude Code
PR 5 of the v7 API plan.
Twelve public entry points answered what is this file. This leaves four —
two questions over two input types.
The four duplicate statics
DecodedFile::list_file_typesandDecodedFile::mimetype(×2 each) were theimplementation;
odr::list_file_typesandodr::mimetypewere one-lineforwards to them. The bodies move up to the free functions and the statics go.
The clearest evidence this was a real fork and not a harmless alias: the
bindings picked different ones.
apple/src/ODRFile.mmcalledodr::DecodedFile::list_file_types,jni/src/jni_core.cppcalledodr::list_file_types, for the same operation.DocumentFile::typeand::metaFour statics that decoded an entire document to read one field, and threw
NoDocumentFilefor anything that was not a document — sotype(some.png)wasan exception rather than
FileType::portable_network_graphics.open(...).file_type()and.file_meta()answer without the narrowing.Bindings
DocumentFile.typeByPath,DocumentFile.metaByPathDocumentFile.type_by_file/type_by_path/meta_by_file/meta_by_pathlistFileTypes/mimetypenow call the free functionsThe python binding's own comment is a small monument to the problem it had —
"
type/metaare overloaded onFileand path, so the address of either isambiguous; name the signature" — four
def_statics existing to disambiguatean overload set that did not need to exist.
Tests
FileTest.documentFileByPathtested the removed statics; rewritten to assertwhat it was actually after, that a path names an odt, through
Odr.open(path).fileType()/.fileMeta().test_file.py's two caseslikewise.
Net −131/+39.
Verified
Full build clean. 222 gtests (
File*,*Csv*,*Markdown*,*Xml*,*Flat*,*Document*), 69 python tests, JNI junit viactest --test-dir jni— all pass.
Migration
DecodedFile::mimetype(path) → odr::mimetype(path) DecodedFile::list_file_types(path) → odr::list_file_types(path) DocumentFile::type(path) → odr::open(path).file_type() DocumentFile::meta(path) → odr::open(path).file_meta()