Skip to content

Commit 39d4f9d

Browse files
authored
Add type annotations for enum parameters in methods (#169)
1 parent f53340f commit 39d4f9d

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

pulsar/__init__.py

+30-31
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,26 @@ def policy(self):
440440
"""
441441
return self._policy
442442

443+
class CryptoKeyReader:
444+
"""
445+
Default crypto key reader implementation
446+
"""
447+
def __init__(self, public_key_path, private_key_path):
448+
"""
449+
Create crypto key reader.
450+
451+
Parameters
452+
----------
453+
454+
public_key_path: str
455+
Path to the public key
456+
private_key_path: str
457+
Path to private key
458+
"""
459+
_check_type(str, public_key_path, 'public_key_path')
460+
_check_type(str, private_key_path, 'private_key_path')
461+
self.cryptoKeyReader = _pulsar.CryptoKeyReader(public_key_path, private_key_path)
462+
443463
class Client:
444464
"""
445465
The Pulsar client. A single client instance can be used to create producers
@@ -574,7 +594,7 @@ def create_producer(self, topic,
574594
schema=schema.BytesSchema(),
575595
initial_sequence_id=None,
576596
send_timeout_millis=30000,
577-
compression_type=CompressionType.NONE,
597+
compression_type: CompressionType = CompressionType.NONE,
578598
max_pending_messages=1000,
579599
max_pending_messages_across_partitions=50000,
580600
block_if_queue_full=False,
@@ -583,13 +603,13 @@ def create_producer(self, topic,
583603
batching_max_allowed_size_in_bytes=128*1024,
584604
batching_max_publish_delay_ms=10,
585605
chunking_enabled=False,
586-
message_routing_mode=PartitionsRoutingMode.RoundRobinDistribution,
606+
message_routing_mode: PartitionsRoutingMode = PartitionsRoutingMode.RoundRobinDistribution,
587607
lazy_start_partitioned_producers=False,
588608
properties=None,
589-
batching_type=BatchingType.Default,
609+
batching_type: BatchingType = BatchingType.Default,
590610
encryption_key=None,
591-
crypto_key_reader=None,
592-
access_mode=ProducerAccessMode.Shared,
611+
crypto_key_reader: CryptoKeyReader = None,
612+
access_mode: ProducerAccessMode = ProducerAccessMode.Shared,
593613
):
594614
"""
595615
Create a new producer on a given topic.
@@ -752,7 +772,7 @@ def create_producer(self, topic,
752772
return p
753773

754774
def subscribe(self, topic, subscription_name,
755-
consumer_type=ConsumerType.Exclusive,
775+
consumer_type: ConsumerType = ConsumerType.Exclusive,
756776
schema=schema.BytesSchema(),
757777
message_listener=None,
758778
receiver_queue_size=1000,
@@ -764,16 +784,16 @@ def subscribe(self, topic, subscription_name,
764784
is_read_compacted=False,
765785
properties=None,
766786
pattern_auto_discovery_period=60,
767-
initial_position=InitialPosition.Latest,
768-
crypto_key_reader=None,
787+
initial_position: InitialPosition = InitialPosition.Latest,
788+
crypto_key_reader: CryptoKeyReader = None,
769789
replicate_subscription_state_enabled=False,
770790
max_pending_chunked_message=10,
771791
auto_ack_oldest_chunked_message_on_queue_full=False,
772792
start_message_id_inclusive=False,
773793
batch_receive_policy=None,
774794
key_shared_policy=None,
775795
batch_index_ack_enabled=False,
776-
regex_subscription_mode=RegexSubscriptionMode.PersistentOnly,
796+
regex_subscription_mode: RegexSubscriptionMode = RegexSubscriptionMode.PersistentOnly,
777797
dead_letter_policy: ConsumerDeadLetterPolicy = None,
778798
):
779799
"""
@@ -966,7 +986,7 @@ def create_reader(self, topic, start_message_id,
966986
reader_name=None,
967987
subscription_role_prefix=None,
968988
is_read_compacted=False,
969-
crypto_key_reader=None,
989+
crypto_key_reader: CryptoKeyReader = None,
970990
start_message_id_inclusive=False
971991
):
972992
"""
@@ -1713,27 +1733,6 @@ def is_connected(self):
17131733
return self._reader.is_connected()
17141734

17151735

1716-
class CryptoKeyReader:
1717-
"""
1718-
Default crypto key reader implementation
1719-
"""
1720-
def __init__(self, public_key_path, private_key_path):
1721-
"""
1722-
Create crypto key reader.
1723-
1724-
Parameters
1725-
----------
1726-
1727-
public_key_path: str
1728-
Path to the public key
1729-
private_key_path: str
1730-
Path to private key
1731-
"""
1732-
_check_type(str, public_key_path, 'public_key_path')
1733-
_check_type(str, private_key_path, 'private_key_path')
1734-
self.cryptoKeyReader = _pulsar.CryptoKeyReader(public_key_path, private_key_path)
1735-
1736-
17371736
class ConsoleLogger:
17381737
"""
17391738
Logger that writes on standard output

0 commit comments

Comments
 (0)