Skip to content

Type the public API#643

Merged
audreyfeldroy merged 1 commit intomainfrom
add-type-annotations
Mar 8, 2026
Merged

Type the public API#643
audreyfeldroy merged 1 commit intomainfrom
add-type-annotations

Conversation

@audreyfeldroy
Copy link
Copy Markdown
Collaborator

Summary

  • Inline type annotations on all public functions: is_binary(), is_binary_string(), get_starting_chunk(), plus internal _compute_features() and the decision tree's is_binary()
  • is_binary() and get_starting_chunk() accept str | bytes | Path, matching what open() already handles
  • Inline annotations instead of .pyi stubs since the project is Python 3.12+

Resolves #626. Supersedes #627. Addresses #628.

Credit to @smheidrich for #627 which first proposed py.typed and type stubs, and to @AlJohri for #628 requesting pathlib.Path support.

Test plan

  • uv run ty check passes
  • uv run ruff check passes
  • uv run pytest passes (213 passed, 5 xfailed)
  • No code changes, only annotations added

…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
@audreyfeldroy audreyfeldroy merged commit 111ae00 into main Mar 8, 2026
9 checks passed
@audreyfeldroy audreyfeldroy deleted the add-type-annotations branch March 8, 2026 13:31
@audreyfeldroy audreyfeldroy mentioned this pull request Mar 8, 2026
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.

Feature request: Type hints for public API

1 participant