Skip to content

typing(index): add parameter annotations for Index base class (#198) - #200

Merged
priya-sundaram-dev merged 1 commit into
priya-sundaram-dev:mainfrom
webdevsamran:type/issue-198-index-base-hints
Sep 19, 2026
Merged

priya-sundaram-dev merged 1 commit into
priya-sundaram-dev:mainfrom
webdevsamran:type/issue-198-index-base-hints

Conversation

@webdevsamran

Copy link
Copy Markdown
Contributor

Summary

Adds parameter type annotations to the seven Index abstract base class methods in src/whoosh/index.py that had return annotations but lacked parameter types, matching the concrete implementations in whoosh.writing and whoosh.filedb.fileindex:

  • add_field(self, fieldname: str, fieldspec: FieldType) -> None
  • remove_field(self, fieldname: str) -> None
  • field_length(self, fieldname: str) -> int
  • max_field_length(self, fieldname: str) -> int
  • reader(self, reuse: IndexReader | None = None) -> IndexReader
  • delete_by_term(self, fieldname: str, text: str, searcher: Searcher | None = None) -> None
  • delete_by_query(self, q: Query, searcher: Searcher | None = None) -> None

Also imported FieldType and Query under TYPE_CHECKING (safe against runtime cycles via from __future__ import annotations).

Updated CHANGELOG.md under ## [Unreleased] -> ### Typing.

Related issues

Fixes #198

Checklist

  • Tests pass locally (pytest tests/) ? 33/33 tests in tests/test_indexing.py pass cleanly
  • Added/updated tests for the change where it makes sense (annotations only, verified via test suite)
  • Updated docs / CHANGELOG if user-facing (CHANGELOG.md updated)
  • I have read the CONTRIBUTING guide

AI-assisted contribution ? implementation drafted with an AI coding agent, reviewed and validated locally before submission.

@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.

Thank you, @webdevsamran — this is exactly what #198 was asking for, and it's a clean, tightly-scoped patch. 🎉

A few things I appreciated while reviewing:

  • The seven parameter annotations match the concrete implementations in whoosh.writing.IndexWriter one-for-one (e.g. add_field(fieldname: str, fieldspec: FieldType), delete_by_term(fieldname: str, text: str, searcher: Searcher | None = None)), so the base class and its subclasses now agree.
  • Correctly kept Index.delete_by_query(...) -> None even though the writer's version returns int — the base method wraps writer() + commit() and doesn't surface the count, so None is right.
  • FieldType and Query imported under TYPE_CHECKING with from __future__ import annotations already in place — no runtime import cycle risk. 👍
  • CHANGELOG entry under [Unreleased] → Typing is exactly the convention we use.

CI is green across the whole matrix (3.10–3.15, 3.14t/3.15t, PyPy, Windows, macOS, ruff, mypy smoke). Merging now — this will go out in the next release with credit to you. Thanks for picking up a good-first-issue and following the CONTRIBUTING flow so carefully; hope to see you around the tracker again.

@priya-sundaram-dev
priya-sundaram-dev merged commit d331b02 into priya-sundaram-dev:main Sep 19, 2026
17 checks passed
@priya-sundaram-dev

Copy link
Copy Markdown
Owner

Merged — thanks again, @webdevsamran! That's two clean typing PRs from you now (#194 and this one), and both landed with zero rework needed. Really appreciate the careful work.

If you'd like to keep going, a couple of directions depending on your mood:

Either is yours if you want it — just comment on the issue and I'll assign it. No pressure at all, and thank you for helping revive this library. 🙏

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: parameter annotations for the Index base class in whoosh.index (good first issue)

2 participants