Skip to content

Add type annotations to ExternalSearchIndex methods#3000

Merged
jonathangreen merged 1 commit intomainfrom
chore/type-annotations-external-search
Jan 23, 2026
Merged

Add type annotations to ExternalSearchIndex methods#3000
jonathangreen merged 1 commit intomainfrom
chore/type-annotations-external-search

Conversation

@jonathangreen
Copy link
Member

Description

Add comprehensive type hints to the ExternalSearchIndex class methods:

  • create_search_doc
  • query_works
  • query_works_multi
  • count_works

Return 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?

  • All existing tests pass
  • Tests updated to work with new return types
  • Type annotations validated with mypy

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

filter: Filter | None = None,
pagination: Pagination | None = None,
debug: bool = False,
) -> Sequence[Hit]:
Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's helpful. Might be handy to work that into the docstring below.

@codecov
Copy link

codecov bot commented Jan 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.98%. Comparing base (1676f62) to head (9cfbca6).
⚠️ Report is 4 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jonathangreen jonathangreen force-pushed the chore/convert-search-base-to-functions branch from a870688 to 1c1d8f0 Compare January 21, 2026 20:48
@jonathangreen jonathangreen changed the base branch from chore/convert-search-base-to-functions to main January 21, 2026 20:49
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.
@jonathangreen jonathangreen force-pushed the chore/type-annotations-external-search branch from 7e1d929 to 9cfbca6 Compare January 21, 2026 20:50
@jonathangreen jonathangreen requested a review from a team January 21, 2026 20:50
Copy link
Contributor

@tdilauro tdilauro left a comment

Choose a reason for hiding this comment

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

☑️ 🚀

filter: Filter | None = None,
pagination: Pagination | None = None,
debug: bool = False,
) -> Sequence[Hit]:
Copy link
Contributor

Choose a reason for hiding this comment

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

That's helpful. Might be handy to work that into the docstring below.

@jonathangreen jonathangreen merged commit d995b16 into main Jan 23, 2026
19 checks passed
@jonathangreen jonathangreen deleted the chore/type-annotations-external-search branch January 23, 2026 22:29
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.

2 participants