Skip to content

Commit 47a43ea

Browse files
committed
Add type annotations for kafka.
1 parent 13587b3 commit 47a43ea

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

kafka/testcontainers/kafka/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class KafkaContainer(DockerContainer):
2626
KAFKA_PORT = 9093
2727
TC_START_SCRIPT = '/tc-start.sh'
2828

29-
def __init__(self, image="confluentinc/cp-kafka:5.4.3", port_to_expose=KAFKA_PORT, **kwargs):
29+
def __init__(self, image: str = "confluentinc/cp-kafka:5.4.3", port_to_expose: int = KAFKA_PORT,
30+
**kwargs) -> None:
3031
super(KafkaContainer, self).__init__(image, **kwargs)
3132
self.port_to_expose = port_to_expose
3233
self.with_exposed_ports(self.port_to_expose)
@@ -42,19 +43,19 @@ def __init__(self, image="confluentinc/cp-kafka:5.4.3", port_to_expose=KAFKA_POR
4243
self.with_env('KAFKA_LOG_FLUSH_INTERVAL_MESSAGES', '10000000')
4344
self.with_env('KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS', '0')
4445

45-
def get_bootstrap_server(self):
46+
def get_bootstrap_server(self) -> str:
4647
host = self.get_container_host_ip()
4748
port = self.get_exposed_port(self.port_to_expose)
4849
return '{}:{}'.format(host, port)
4950

5051
@wait_container_is_ready(UnrecognizedBrokerVersion, NoBrokersAvailable, KafkaError, ValueError)
51-
def _connect(self):
52+
def _connect(self) -> None:
5253
bootstrap_server = self.get_bootstrap_server()
5354
consumer = KafkaConsumer(group_id='test', bootstrap_servers=[bootstrap_server])
5455
if not consumer.bootstrap_connected():
5556
raise KafkaError("Unable to connect with kafka container!")
5657

57-
def tc_start(self):
58+
def tc_start(self) -> None:
5859
host = self.get_container_host_ip()
5960
port = self.get_exposed_port(self.port_to_expose)
6061
listeners = 'PLAINTEXT://{}:{},BROKER://$(hostname -i):9092'.format(host, port)
@@ -78,7 +79,7 @@ def tc_start(self):
7879
)
7980
self.create_file(data, KafkaContainer.TC_START_SCRIPT)
8081

81-
def start(self):
82+
def start(self) -> "KafkaContainer":
8283
script = KafkaContainer.TC_START_SCRIPT
8384
command = 'sh -c "while [ ! -f {} ]; do sleep 0.1; done; sh {}"'.format(script, script)
8485
self.with_command(command)
@@ -87,7 +88,7 @@ def start(self):
8788
self._connect()
8889
return self
8990

90-
def create_file(self, content: bytes, path: str):
91+
def create_file(self, content: bytes, path: str) -> None:
9192
with BytesIO() as archive, tarfile.TarFile(fileobj=archive, mode="w") as tar:
9293
tarinfo = tarfile.TarInfo(name=path)
9394
tarinfo.size = len(content)

0 commit comments

Comments
 (0)