Add type annotations to ExternalSearchIndex methods#3000
Conversation
| filter: Filter | None = None, | ||
| pagination: Pagination | None = None, | ||
| debug: bool = False, | ||
| ) -> Sequence[Hit]: |
There was a problem hiding this comment.
This return type is actually an OpensearchPy Result, which implements the Sequence interface, but has some extra methods. Since Result types as Any (lacks annotations), I thought I'd type hint this as Sequence. That gives us stricter typing, but means that we can't access some of the properties on Result like hits.
Everywhere in production code this is fine, but we use .hits in tests a couple places, so I updated those spots.
There was a problem hiding this comment.
That's helpful. Might be handy to work that into the docstring below.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3000 +/- ##
=======================================
Coverage 92.97% 92.98%
=======================================
Files 459 459
Lines 43276 43278 +2
Branches 6034 6034
=======================================
+ Hits 40238 40240 +2
Misses 1966 1966
Partials 1072 1072 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a870688 to
1c1d8f0
Compare
Type the create_search_doc, query_works, query_works_multi, and count_works methods. Return Sequence[Hit] from query methods for clearer typing. Update tests to work with the new return types.
7e1d929 to
9cfbca6
Compare
| filter: Filter | None = None, | ||
| pagination: Pagination | None = None, | ||
| debug: bool = False, | ||
| ) -> Sequence[Hit]: |
There was a problem hiding this comment.
That's helpful. Might be handy to work that into the docstring below.
Description
Add comprehensive type hints to the ExternalSearchIndex class methods:
create_search_docquery_worksquery_works_multicount_worksReturn
Sequence[Hit]from query methods for clearer typing.Motivation and Context
Continues the type annotation work in the search module, enabling stricter type checking and improving IDE support.
How Has This Been Tested?
Checklist