Skip to content

Commit

Permalink
Deprecate loop argument to AIOKafkaConsumer/AIOKafkaProducer (#699)
Browse files Browse the repository at this point in the history
* Deprecate loop argument to AIOKafkaConsumer/AIOKafkaProducer

* Add clause on deprecation to CHANGES
  • Loading branch information
ods committed Dec 21, 2020
1 parent 306ae6e commit 5d9af4d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Fix initialization without running loop
693.doc
Update docs and examples to not use deprecated practices like passing loop explicitly

699.removal
Add deprecation warning when loop argument to AIOKafkaConsumer and AIOKafkaProducer is passed.
It's scheduled for removal in 0.8.0 as a preparation step towards upcoming Python 3.10


0.7.0 (2020-10-28)
==================
Expand Down
4 changes: 4 additions & 0 deletions aiokafka/consumer/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ def __init__(self, *topics, loop=None,
sasl_oauth_token_provider=None):
if loop is None:
loop = get_running_loop()
else:
warnings.warn("The loop argument is deprecated since 0.7.1, "
"and scheduled for removal in 0.8.0",
DeprecationWarning, stacklevel=2)

if max_poll_records is not None and (
not isinstance(max_poll_records, int) or max_poll_records < 1):
Expand Down
4 changes: 4 additions & 0 deletions aiokafka/producer/producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ def __init__(self, *, loop=None, bootstrap_servers='localhost',
sasl_oauth_token_provider=None):
if loop is None:
loop = get_running_loop()
else:
warnings.warn("The loop argument is deprecated since 0.7.1, "
"and scheduled for removal in 0.8.0",
DeprecationWarning, stacklevel=2)
if loop.get_debug():
self._source_traceback = traceback.extract_stack(sys._getframe(1))
self._loop = loop
Expand Down
5 changes: 3 additions & 2 deletions tests/test_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ async def test_simple_consumer(self):
@run_in_thread
def test_create_consumer_no_running_loop(self):
loop = asyncio.new_event_loop()
consumer = AIOKafkaConsumer(
self.topic, bootstrap_servers=self.hosts, loop=loop)
with pytest.deprecated_call():
consumer = AIOKafkaConsumer(
self.topic, bootstrap_servers=self.hosts, loop=loop)
loop.run_until_complete(consumer.start())
try:
loop.run_until_complete(
Expand Down
3 changes: 2 additions & 1 deletion tests/test_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ async def test_producer_send(self):
@run_in_thread
def test_create_producer_no_running_loop(self):
loop = asyncio.new_event_loop()
producer = AIOKafkaProducer(bootstrap_servers=self.hosts, loop=loop)
with pytest.deprecated_call():
producer = AIOKafkaProducer(bootstrap_servers=self.hosts, loop=loop)
loop.run_until_complete(producer.start())
try:
future = loop.run_until_complete(
Expand Down

0 comments on commit 5d9af4d

Please sign in to comment.