Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate loop argument to AIOKafkaConsumer/AIOKafkaProducer #699

Merged
merged 2 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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