Repository navigation
typing(index): add parameter annotations for Index base class (#198) - #200
Conversation
…sundaram-dev#198) Signed-off-by: webdevsamran <[email protected]>
priya-sundaram-dev
left a comment
There was a problem hiding this comment.
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.IndexWriterone-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(...) -> Noneeven though the writer's version returnsint— the base method wrapswriter()+commit()and doesn't surface the count, soNoneis right. FieldTypeandQueryimported underTYPE_CHECKINGwithfrom __future__ import annotationsalready in place — no runtime import cycle risk. 👍- CHANGELOG entry under
[Unreleased] → Typingis 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.
|
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. 🙏 |
Summary
Adds parameter type annotations to the seven
Indexabstract base class methods insrc/whoosh/index.pythat had return annotations but lacked parameter types, matching the concrete implementations inwhoosh.writingandwhoosh.filedb.fileindex:add_field(self, fieldname: str, fieldspec: FieldType) -> Noneremove_field(self, fieldname: str) -> Nonefield_length(self, fieldname: str) -> intmax_field_length(self, fieldname: str) -> intreader(self, reuse: IndexReader | None = None) -> IndexReaderdelete_by_term(self, fieldname: str, text: str, searcher: Searcher | None = None) -> Nonedelete_by_query(self, q: Query, searcher: Searcher | None = None) -> NoneAlso imported
FieldTypeandQueryunderTYPE_CHECKING(safe against runtime cycles viafrom __future__ import annotations).Updated
CHANGELOG.mdunder## [Unreleased] -> ### Typing.Related issues
Fixes #198
Checklist
pytest tests/) ? 33/33 tests intests/test_indexing.pypass cleanlyCHANGELOG.mdupdated)AI-assisted contribution ? implementation drafted with an AI coding agent, reviewed and validated locally before submission.