Merged
Conversation
…d comes out is_binary() and get_starting_chunk() accept str, bytes, and Path, matching what Python's open() already handles. is_binary_string() takes bytes, _compute_features() takes bytes and returns list[float], and the decision tree's is_binary() takes list[float]. Resolves #626 (type hints for public API). Supersedes #627 (stub files, no longer needed since Python 2 was dropped). Addresses #628 (pathlib.Path support, which already worked but is now documented in the types). Key design decisions: - Inline annotations instead of .pyi stubs, since the project is Python 3.12+ - str | bytes | Path rather than os.PathLike[str] to match how people actually call the function (pathlib.Path, not custom PathLike objects) - No int (file descriptors): technically works via open() but no demonstrated use case and no error handling for bad fds
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.
Summary
is_binary(),is_binary_string(),get_starting_chunk(), plus internal_compute_features()and the decision tree'sis_binary()is_binary()andget_starting_chunk()acceptstr | bytes | Path, matching whatopen()already handles.pyistubs since the project is Python 3.12+Resolves #626. Supersedes #627. Addresses #628.
Credit to @smheidrich for #627 which first proposed
py.typedand type stubs, and to @AlJohri for #628 requesting pathlib.Path support.Test plan
uv run ty checkpassesuv run ruff checkpassesuv run pytestpasses (213 passed, 5 xfailed)