Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge .pyi type stubs inline #563

Merged
merged 17 commits into from
Nov 6, 2023
Merged

Conversation

dblock
Copy link
Member

@dblock dblock commented Nov 1, 2023

Description

Merge .pyi files inline for those files that were previously covered by mypy. Many Any that should not be, but it gets us started to have a fully typed library that is edited at the same time as code. This should greatly improve code clarity, maintainability, and enable better static analysis.

I wasn't sure whether this is a good idea, so I found some other projects merging stubs.

Issues Resolved

Closes #536.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: dblock <[email protected]>
@dblock dblock marked this pull request as draft November 1, 2023 17:11
Copy link

codecov bot commented Nov 1, 2023

Codecov Report

Merging #563 (a97845f) into main (0d8a23d) will increase coverage by 0.58%.
The diff coverage is 96.78%.

@@            Coverage Diff             @@
##             main     #563      +/-   ##
==========================================
+ Coverage   71.10%   71.69%   +0.58%     
==========================================
  Files          85       87       +2     
  Lines        7774     7875     +101     
==========================================
+ Hits         5528     5646     +118     
+ Misses       2246     2229      -17     
Files Coverage Δ
opensearchpy/__init__.py 100.00% <100.00%> (ø)
opensearchpy/_async/client/_patch.py 48.14% <100.00%> (+1.99%) ⬆️
opensearchpy/_async/client/client.py 100.00% <100.00%> (ø)
opensearchpy/_async/client/cluster.py 52.32% <100.00%> (+0.56%) ⬆️
opensearchpy/_async/client/dangling_indices.py 56.25% <100.00%> (+2.91%) ⬆️
opensearchpy/_async/client/features.py 77.77% <100.00%> (+2.77%) ⬆️
opensearchpy/_async/client/indices.py 46.47% <100.00%> (+0.25%) ⬆️
opensearchpy/_async/client/ingest.py 52.00% <100.00%> (+2.00%) ⬆️
opensearchpy/_async/client/nodes.py 65.00% <100.00%> (+1.84%) ⬆️
opensearchpy/_async/client/plugins.py 95.00% <100.00%> (+1.25%) ⬆️
... and 74 more

@dblock dblock marked this pull request as ready for review November 1, 2023 20:06
@dblock dblock changed the title Merge .pyi files inline. Merge .pyi stubs inline. Nov 1, 2023
@dblock dblock changed the title Merge .pyi stubs inline. Merge .pyi type stubs inline Nov 1, 2023
@dblock
Copy link
Member Author

dblock commented Nov 3, 2023

@saimedhi this is ready for review, FYI

Copy link
Collaborator

@saimedhi saimedhi left a comment

Choose a reason for hiding this comment

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

@dblock, I've reviewed the PR, and from what I understand, API types are added automatically through the generator, while for tests and other files, we add them manually. I've made a few requested changes, and if you agree with them, please make the changes. Thank you for your contribution!

@@ -71,34 +71,34 @@ async def test_async(client_count=1, item_count=1):
await asyncio.gather(*[client.close() for client in clients])


def test(item_count=1, client_count=1):
def test(item_count: int = 1, client_count: int = 1) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

type annotation missing for "test_async" function in this file.

Copy link
Member Author

Choose a reason for hiding this comment

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

There's another 1000 errors from the missing files that were not previously checked by mypy, including benchmarks and tests. Could we merge this one and I'll work on the rest?

opensearchpy/__init__.py Outdated Show resolved Hide resolved
benchmarks/bench_async.py Show resolved Hide resolved
benchmarks/bench_info_sync.py Show resolved Hide resolved
benchmarks/bench_sync.py Show resolved Hide resolved
Signed-off-by: dblock <[email protected]>
@dblock
Copy link
Member Author

dblock commented Nov 6, 2023

@saimedhi Thanks for the CR! I edited the description to say "Merge .pyi files inline for those files that were previously covered by mypy." I'd prefer we merge this as an intermediate step, but lmk if you feel strongly otherwise. Opened #564 to add types to the rest of the code.

@saimedhi saimedhi merged commit dcb79cc into opensearch-project:main Nov 6, 2023
54 checks passed
@dblock dblock deleted the merge-pyi branch November 6, 2023 21:21
potiuk added a commit to potiuk/airflow that referenced this pull request Nov 16, 2023
The new opensearch-py 2.4.1 added mypy stubs in
opensearch-project/opensearch-py#563 and
they detected an error in our example (and they cause mypy error
when the new version is used)
potiuk added a commit to apache/airflow that referenced this pull request Nov 16, 2023
The new opensearch-py 2.4.1 added mypy stubs in
opensearch-project/opensearch-py#563 and
they detected an error in our example (and they cause mypy error
when the new version is used)
roma2023 pushed a commit to roma2023/opensearch-py that referenced this pull request Dec 28, 2023
* Merged types into .py code.

Signed-off-by: dblock <[email protected]>

* Fix: nox -rs generate.

Signed-off-by: dblock <[email protected]>

* Updated CHANGELOG.

Signed-off-by: dblock <[email protected]>

* Use lowest common python version for lint.

Signed-off-by: dblock <[email protected]>

* Fix: don't typeshed.

Signed-off-by: dblock <[email protected]>

* Removed unneeded comment.

Signed-off-by: dblock <[email protected]>

* Simplify OPENSEARCH_URL.

Signed-off-by: dblock <[email protected]>

* Fix: positional ignore_status used as chunk_size.

Signed-off-by: dblock <[email protected]>

* Fix: parse version string.

Signed-off-by: dblock <[email protected]>

* Remove future annotations for Python 3.6.

Signed-off-by: dblock <[email protected]>

* Fix: types in documentation.

Signed-off-by: dblock <[email protected]>

* Improve CHANGELOG text.

Signed-off-by: dblock <[email protected]>

* Re-added missing separator.

Signed-off-by: dblock <[email protected]>

* Remove duplicate licenses.

Signed-off-by: dblock <[email protected]>

* Get rid of Optional[Any].

Signed-off-by: dblock <[email protected]>

* Fix docs with AsyncOpenSearch.

Signed-off-by: dblock <[email protected]>

* Fix: undo comment.

Signed-off-by: dblock <[email protected]>

---------

Signed-off-by: dblock <[email protected]>
Signed-off-by: roma2023 <[email protected]>
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Jul 18, 2024
The new opensearch-py 2.4.1 added mypy stubs in
opensearch-project/opensearch-py#563 and
they detected an error in our example (and they cause mypy error
when the new version is used)

GitOrigin-RevId: dffe04ada4c05a3e29422f6ea92625c6e040bf10
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Sep 20, 2024
The new opensearch-py 2.4.1 added mypy stubs in
opensearch-project/opensearch-py#563 and
they detected an error in our example (and they cause mypy error
when the new version is used)

GitOrigin-RevId: dffe04ada4c05a3e29422f6ea92625c6e040bf10
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Nov 8, 2024
The new opensearch-py 2.4.1 added mypy stubs in
opensearch-project/opensearch-py#563 and
they detected an error in our example (and they cause mypy error
when the new version is used)

GitOrigin-RevId: dffe04ada4c05a3e29422f6ea92625c6e040bf10
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.

[PROPOSAL] Merge .pyi types inline
2 participants