Skip to content

Commit 84bc493

Browse files
committed
Add type hints to APIs
1 parent e2ae6de commit 84bc493

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+12293
-36
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pyi binary

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ include README.rst
77
include README
88
include tox.ini
99
include setup.py
10+
recursive-include elasticsearch* py.typed
1011
recursive-include docs *
1112

1213
prune docs/_build

elasticsearch/__init__.pyi

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
import sys
6+
from typing import Tuple
7+
8+
from .client import Elasticsearch as Elasticsearch
9+
from .transport import Transport as Transport
10+
from .connection_pool import (
11+
ConnectionPool as ConnectionPool,
12+
ConnectionSelector as ConnectionSelector,
13+
RoundRobinSelector as RoundRobinSelector,
14+
)
15+
from .serializer import JSONSerializer as JSONSerializer
16+
from .connection import (
17+
Connection as Connection,
18+
RequestsHttpConnection as RequestsHttpConnection,
19+
Urllib3HttpConnection as Urllib3HttpConnection,
20+
)
21+
from .exceptions import (
22+
ImproperlyConfigured as ImproperlyConfigured,
23+
ElasticsearchException as ElasticsearchException,
24+
SerializationError as SerializationError,
25+
TransportError as TransportError,
26+
NotFoundError as NotFoundError,
27+
ConflictError as ConflictError,
28+
RequestError as RequestError,
29+
ConnectionError as ConnectionError,
30+
SSLError as SSLError,
31+
ConnectionTimeout as ConnectionTimeout,
32+
AuthenticationException as AuthenticationException,
33+
AuthorizationException as AuthorizationException,
34+
ElasticsearchDeprecationWarning as ElasticsearchDeprecationWarning,
35+
)
36+
37+
try:
38+
if sys.version_info < (3, 6):
39+
raise ImportError
40+
41+
from ._async.http_aiohttp import AIOHttpConnection as AIOHttpConnection
42+
from ._async.transport import AsyncTransport as AsyncTransport
43+
from ._async.client import AsyncElasticsearch as AsyncElasticsearch
44+
except (ImportError, SyntaxError):
45+
pass
46+
47+
VERSION: Tuple[int, int, int]
48+
__version__: Tuple[int, int, int]
49+
__versionstr__: str
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
# type: ignore
6+
7+
# This file exists for the sole reason of making mypy not
8+
# complain about type issues to do with 'aiohttp' and 'yarl'.
9+
# We're in a catch-22 situation:
10+
# - If we use 'type: ignore' on 'import aiohttp' and it's not installed
11+
# mypy will complain that the annotation is unnecessary.
12+
# - If we don't use 'type: ignore' on 'import aiohttp' and it
13+
# it's not installed mypy will complain that it can't find
14+
# type hints for aiohttp.
15+
# So to make mypy happy we move all our 'extra' imports here
16+
# and add a global 'type: ignore' which mypy never complains
17+
# about being unnecessary.
18+
19+
import aiohttp
20+
import aiohttp.client_exceptions as aiohttp_exceptions
21+
import yarl
22+
23+
__all__ = ["aiohttp", "aiohttp_exceptions", "yarl"]

0 commit comments

Comments
 (0)