opensearch-project / opensearch-py

Python Client for OpenSearch
https://opensearch.org/docs/latest/clients/python/
Apache License 2.0
350 stars 175 forks source link

Add plugin clients typing to the opensearch client #440

Closed florianvazelle closed 12 months ago

florianvazelle commented 1 year ago

Description

I add the clients of the various plugins to the typing of the main client (OpenSearch).

codecov[bot] commented 1 year ago

Codecov Report

Merging #440 (00b0e34) into main (4dba35d) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #440   +/-   ##
=======================================
  Coverage   71.49%   71.49%           
=======================================
  Files          81       81           
  Lines        7668     7668           
=======================================
  Hits         5482     5482           
  Misses       2186     2186           
saimedhi commented 1 year ago

Hello @florianvazelle, please respond to the following https://github.com/opensearch-project/opensearch-py/pull/399#issuecomment-1642789791. Thanks

saimedhi commented 1 year ago

@florianvazelle, Could you please finish this PR when you have a moment? Thank you!

florianvazelle commented 1 year ago

Hi @saimedhi, sorry I'm taking some time to study solutions to have a correct stubs package.

The only real way I've found is to use stubtest, but that only ensures that the definitions in the stubs package are defined in the package at runtime too (no extra definitions) and logical with what is defined in the package at runtime (same parameters ...), but if a definition is missing in the stubs package it won't be raised.

I'm going to add this to the linting commands anyway.

To prevent oversights from happening again, I suggest opening a new issue to study solutions, and we'll can then merge this PR.

dblock commented 12 months ago

@florianvazelle I finished #536 so types are back in the game. Do you want to finish this?

I am not sure we need to declare types like this here. For other types we just do self.cat = CatClient(self) and I think the Python type system is smart enough to figure out that cat is always CatClient, but I could be wrong. So either add types as proposed here or remove the declaration?

florianvazelle commented 12 months ago

@dblock I think you fix my issue with #536, I'm closing this PR thank you :wink:

dblock commented 12 months ago

Did I? This code says Any, should it be typed or should the declaration be removed?

https://github.com/opensearch-project/opensearch-py/blob/d8dc5474b7e7e2b443d9858c21d8f7be93306704/opensearchpy/client/plugins.py#L21