Skip to content

Commit 256ce17

Browse files
authored
Type annotations for helpers (#989)
* Type annotations for helpers * Fix references * Fix "class reference target not found: typing_extensions.Buffer" error * Fix "object is not subscriptable" in Python 3.8
1 parent bd62ee0 commit 256ce17

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ DIFF_BRANCH=origin/master
88
FORMATTED_AREAS=\
99
aiokafka/codec.py \
1010
aiokafka/errors.py \
11+
aiokafka/helpers.py \
1112
aiokafka/structs.py \
1213
aiokafka/util.py \
1314
tests/test_codec.py

aiokafka/consumer/consumer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ async def commit(self, offsets=None):
573573
Will now raise :exc:`~aiokafka.errors.CommitFailedError` in case
574574
membership changed, as (possibly) this partition is handled by
575575
another consumer.
576+
577+
.. _kafka-python: https://github.com/dpkp/kafka-python
576578
"""
577579
if self._group_id is None:
578580
raise IllegalOperation("Requires group_id")

aiokafka/helpers.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
"""
2-
.. _kafka-python: https://github.com/dpkp/kafka-python
3-
"""
1+
from __future__ import annotations
42

53
import logging
6-
from ssl import Purpose, create_default_context
4+
from os import PathLike
5+
from ssl import Purpose, SSLContext, create_default_context
6+
from typing import Callable, Union
7+
8+
from typing_extensions import Buffer
79

810
log = logging.getLogger(__name__)
911

1012

1113
def create_ssl_context(
1214
*,
13-
cafile=None,
14-
capath=None,
15-
cadata=None,
16-
certfile=None,
17-
keyfile=None,
18-
password=None,
19-
crlfile=None,
20-
):
15+
cafile: Union[str, bytes, PathLike[str], PathLike[bytes], None] = None,
16+
capath: Union[str, bytes, PathLike[str], PathLike[bytes], None] = None,
17+
cadata: Union[str, Buffer, None] = None,
18+
certfile: Union[str, bytes, PathLike[str], PathLike[bytes], None] = None,
19+
keyfile: Union[str, bytes, PathLike[str], PathLike[bytes], None] = None,
20+
password: Union[
21+
Callable[[], Union[str, bytes, bytearray]], str, bytes, bytearray, None
22+
] = None,
23+
) -> SSLContext:
2124
"""
2225
Simple helper, that creates an :class:`~ssl.SSLContext` based on params similar to
2326
those in `kafka-python`_, but with some restrictions like:
@@ -54,6 +57,7 @@ def create_ssl_context(
5457
:meth:`~ssl.SSLContext.load_cert_chain`.
5558
Default: :data:`None`.
5659
60+
.. _kafka-python: https://github.com/dpkp/kafka-python
5761
"""
5862
if cafile or capath:
5963
log.info("Loading SSL CA from %s", cafile or capath)

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def get_version(release):
8686

8787
# General information about the project.
8888
project = 'aiokafka'
89-
copyright = '2015-2017, Aio-libs contributors'
89+
copyright = '2015-2024, Aio-libs contributors'
9090

9191
# The version info for the project you're documenting, acts as replacement for
9292
# |version| and |release|, also used in various other places throughout the
@@ -119,6 +119,7 @@ def get_version(release):
119119
("py:class", "KT"),
120120
("py:class", "Optional[~ VT]"),
121121
("py:class", "VT"),
122+
("py:class", "typing_extensions.Buffer"),
122123
]
123124

124125
# If true, '()' will be appended to :func: etc. cross-reference text.

0 commit comments

Comments
 (0)