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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Generate `nodes` client from API specs ([#514](https://github.com/opensearch-project/opensearch-py/pull/514))
- Generate `cat` client from API specs ([#529](https://github.com/opensearch-project/opensearch-py/pull/529))
- Use API generator for all APIs ([#551](https://github.com/opensearch-project/opensearch-py/pull/551))
- Merge `.pyi` type stubs inline ([#563](https://github.com/opensearch-project/opensearch-py/pull/563))
### Deprecated
- Deprecated point-in-time APIs (list_all_point_in_time, create_point_in_time, delete_point_in_time) and Security Client APIs (health_check and update_audit_config) ([#502](https://github.com/opensearch-project/opensearch-py/pull/502))
### Removed
Expand Down
4 changes: 3 additions & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ If you want to auto-start one, the following will start a new instance and run t
If your OpenSearch docker instance is running, you can execute the test suite directly.

```
$ nox -rs test
$ nox -rs test-3.9
```

Substitute `3.9` with your Python version above, or use `nox -rs test` to run with multiple.

To run tests against different versions of OpenSearch, use `run-tests [with/without security] [version]`:

```
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include LICENSE
include MANIFEST.in
include README.md
include setup.py
recursive-include opensearch* py.typed *.pyi
recursive-include opensearch* py.typed

prune test_opensearch
recursive-exclude * __pycache__
Expand Down
16 changes: 8 additions & 8 deletions benchmarks/bench_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
item_count = 100


async def index_records(client, item_count):
async def index_records(client, item_count) -> None:
dblock marked this conversation as resolved.
Show resolved Hide resolved
await asyncio.gather(
*[
client.index(
Expand Down Expand Up @@ -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?

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(test_async(item_count, client_count))
loop.close()


def test_1():
def test_1() -> None:
test(1, 32 * item_count)


def test_2():
def test_2() -> None:
test(2, 16 * item_count)


def test_4():
def test_4() -> None:
test(4, 8 * item_count)


def test_8():
def test_8() -> None:
test(8, 4 * item_count)


def test_16():
def test_16() -> None:
test(16, 2 * item_count)


def test_32():
def test_32() -> None:
test(32, item_count)


Expand Down
10 changes: 5 additions & 5 deletions benchmarks/bench_info_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ def test(thread_count=1, request_count=1, client_count=1):
print(f"latency={latency}")


def test_1():
def test_1() -> None:
dblock marked this conversation as resolved.
Show resolved Hide resolved
test(1, 32 * request_count, 1)


def test_2():
def test_2() -> None:
test(2, 16 * request_count, 2)


def test_4():
def test_4() -> None:
test(4, 8 * request_count, 3)


def test_8():
def test_8() -> None:
test(8, 4 * request_count, 8)


def test_32():
def test_32() -> None:
test(32, request_count, 32)


Expand Down
10 changes: 5 additions & 5 deletions benchmarks/bench_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,23 @@ def test(thread_count=1, item_count=1, client_count=1):
print(f"{count}, latency={latency}")

dblock marked this conversation as resolved.
Show resolved Hide resolved

def test_1():
def test_1() -> None:
test(1, 32 * item_count, 1)


def test_2():
def test_2() -> None:
test(2, 16 * item_count, 2)


def test_4():
def test_4() -> None:
test(4, 8 * item_count, 3)


def test_8():
def test_8() -> None:
test(8, 4 * item_count, 8)


def test_32():
def test_32() -> None:
test(32, item_count, 32)


Expand Down
23 changes: 16 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@


@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"])
def test(session):
def test(session) -> None:
session.install(".")
session.install("-r", "dev-requirements.txt")

session.run("python", "setup.py", "test")


@nox.session()
def format(session):
def format(session) -> None:
session.install("black", "isort")

session.run("isort", "--profile=black", *SOURCE_FILES)
Expand All @@ -59,9 +59,18 @@ def format(session):
lint(session)


@nox.session()
def lint(session):
session.install("flake8", "black", "mypy", "isort", "types-requests", "types-six")
@nox.session(python=["3.7"])
def lint(session) -> None:
session.install(
"flake8",
"black",
"mypy",
"isort",
"types-requests",
"types-six",
"types-simplejson",
"types-python-dateutil",
)

session.run("isort", "--check", "--profile=black", *SOURCE_FILES)
session.run("black", "--target-version=py33", "--check", *SOURCE_FILES)
Expand All @@ -85,7 +94,7 @@ def lint(session):


@nox.session()
def docs(session):
def docs(session) -> None:
session.install(".")
session.install(
"-rdev-requirements.txt", "sphinx-rtd-theme", "sphinx-autodoc-typehints"
Expand All @@ -94,7 +103,7 @@ def docs(session):


@nox.session()
def generate(session):
def generate(session) -> None:
session.install("-rdev-requirements.txt")
session.run("python", "utils/generate-api.py")
format(session)
16 changes: 6 additions & 10 deletions opensearchpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,25 @@

import logging
import re
import sys
import warnings

from ._version import __versionstr__

_major, _minor, _patch = [
int(x) for x in re.search(r"^(\d+)\.(\d+)\.(\d+)", __versionstr__).groups()
int(x) for x in re.search(r"^(\d+)\.(\d+)\.(\d+)", __versionstr__).groups() # type: ignore
]

VERSION = __version__ = (_major, _minor, _patch)

logger = logging.getLogger("opensearch")
logger.addHandler(logging.NullHandler())

from ._async.client import AsyncOpenSearch
from ._async.http_aiohttp import AIOHttpConnection, AsyncConnection
from ._async.transport import AsyncTransport
from .client import OpenSearch
from .connection import (
AsyncHttpConnection,
Connection,
RequestsHttpConnection,
Urllib3HttpConnection,
Expand Down Expand Up @@ -247,14 +251,6 @@
"normalizer",
"token_filter",
"tokenizer",
]

from ._async.client import AsyncOpenSearch
from ._async.http_aiohttp import AIOHttpConnection, AsyncConnection
from ._async.transport import AsyncTransport
from .connection import AsyncHttpConnection

__all__ += [
"AIOHttpConnection",
"AsyncConnection",
"AsyncTransport",
Expand Down
132 changes: 0 additions & 132 deletions opensearchpy/__init__.pyi

This file was deleted.

Loading
Loading