Visitar URL original
feat(typing): add type annotations to whoosh.util.numeric by webdevsamran · Pull Request #172 · priya-sundaram-dev/whoosh · GitHub
Skip to content

feat(typing): add type annotations to whoosh.util.numeric - #172

Merged
priya-sundaram-dev merged 1 commit into
priya-sundaram-dev:mainfrom
webdevsamran:fix/issue-171
Sep 3, 2026
Merged

priya-sundaram-dev merged 1 commit into
priya-sundaram-dev:mainfrom
webdevsamran:fix/issue-171

Conversation

@webdevsamran

Copy link
Copy Markdown
Contributor

Fixes #171

Adds parameter and return type annotations to all public functions in src/whoosh/util/numeric.py:

  • bits_required(maxnum: int) -> int
  • typecode_required(maxnum: int) -> str
  • max_value(bitcount: int) -> int
  • bytes_for_bits(bitcount: int) -> int
  • to_sortable(numtype: type[int | float], intsize: int, signed: bool, x: float) -> int
  • from_sortable(numtype: type[int | float], intsize: int, signed: bool, x: int) -> int | float
  • float_to_sortable_long(x: float, signed: bool) -> int
  • sortable_long_to_float(x: int, signed: bool) -> float
  • float_to_byte(value: float, mantissabits: int = 5, zeroexp: int = 2) -> bytes
  • byte_to_float(b: bytes | int, mantissabits: int = 5, zeroexp: int = 2) -> float
  • length_to_byte(length: int | None) -> int

Also records the update under ## [Unreleased] in CHANGELOG.md. No runtime behavior is changed.

Verified with ruff check and ruff format (all checks pass).

@priya-sundaram-dev priya-sundaram-dev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @webdevsamran — this is exactly what #171 asked for, and cleanly done.

A few things I appreciated:

  • The from __future__ import annotations import so the type[int | float] / int | float syntax works on all supported Pythons.
  • The defensive int(x) / float(x) coercions in to_sortable — they make the runtime match the annotated return types without changing behaviour on any real call path. Nice touch.
  • CHANGELOG entry under [Unreleased] with the issue reference.

Full CI matrix is green (3.10–3.15, free-threaded 3.14t/3.15t, mypy smoke, ruff). Merging. This is a great first contribution — if you'd like another, #121 tracks the broader typing effort and there are more whoosh.util.* modules in the same spirit.

@priya-sundaram-dev
priya-sundaram-dev merged commit 6bfb2a7 into priya-sundaram-dev:main Sep 3, 2026
16 checks passed
priya-sundaram-dev added a commit that referenced this pull request Sep 12, 2026
Add type hints to the caching decorators using a Callable-bound TypeVar
(_F) so the wrapped function's signature is preserved for callers.
Annotate internal cache dicts/Counter and the cache_info/cache_clear
helpers. Continues the gradual-typing series (#172/#175/#179/#186).
priya-sundaram-dev added a commit that referenced this pull request Sep 12, 2026
Add type hints to whoosh.util package init: random_name/random_bytes,
make_binary_tree/make_weighted_tree, fib (+ _fib_cache), the now callable,
and the synchronized/unclosed decorators (signature-preserving _F TypeVar).
Continues the gradual-typing series (#172/#175/#179/#186, filelock, cache).
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.

Type hints for whoosh.util.numeric (good first issue)

2 participants