Repository navigation
Fix confluent_kafka.aio import on Python 3.8 - #2401
Closed
Pierre-Yves Le Borgne (pylaterreur) wants to merge 3 commits into
Closed
Pierre-Yves Le Borgne (pylaterreur) wants to merge 3 commits into
Pierre-Yves Le Borgne (pylaterreur) wants to merge 3 commits into
Conversation
azure_client imports the azure_driver module for its key version helpers, and azure_driver imported the AzureKmsClient class from azure_client. Importing azure_client before azure_driver therefore failed on every Python version with "ImportError: cannot import name 'AzureKmsClient' from partially initialized module"; for example, tests/schema_registry/test_azure_client.py fails at collection when run on its own. Import the azure_client module in azure_driver as well, so the cycle resolves whichever module is imported first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN
On Python 3.8, `import confluent_kafka.aio` raised "TypeError: 'type' object is not subscriptable", which also stopped the unit tests at collection. asyncio.Future is only subscriptable from Python 3.9, and three modules of the asyncio producer use asyncio.Future[Any] in annotations that are evaluated at runtime: the MessageBatch fields, function signatures, and the callback factory that _assign_future_callbacks() defines for each message. Releases 2.13.0 to 2.16.0 are affected; pyproject.toml declares Python >= 3.8 and cp38 wheels are published. Add `from __future__ import annotations` to these modules, so their annotations are not evaluated, and add a test that imports every submodule in a fresh interpreter, skipping those whose optional dependencies are not installed. On Python 3.8 the test fails without this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN
Pierre-Yves Le Borgne (pylaterreur)
requested review from
a team and
Matthew Seal (MSeal)
as code owners
October 27, 2026 01:50
|
🎉 All Contributor License Agreements have been signed. Ready to merge. |
# Conflicts: # CHANGELOG.md
2 tasks done
Contributor
Author
1 of 2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
import confluent_kafka.aiofails on Python 3.8 withTypeError: 'type' object is not subscriptable(2.13.0 to 2.16.0 and master), althoughrequires-pythonis>=3.8and cp38 wheels are published.asyncio.Futureis only subscriptable from 3.9, and three modules of the asyncio producer useasyncio.Future[Any]in annotations that are evaluated at runtime: theMessageBatchfields, function signatures, and the callback factory that_assign_future_callbacks()defines for each message. This addsfrom __future__ import annotationsto those modules.The new
tests/test_imports.pyimports every submodule in a fresh interpreter, skipping modules whose optional dependencies are not installed. It also found a circular import: importingazurekms.azure_clientbeforeazurekms.azure_driverraisesImportErroron any Python version, sopytest tests/schema_registry/test_azure_client.pyfails at collection when run on its own.azure_drivernow imports theazure_clientmodule rather than the class, asazure_clientalready does forazure_driver.Checklist
confluent_kafka.aiocan be imported on Python 3.8 again. No API change.tests/test_imports.py, which fails on 3.8 without this change.Test & Review
pytest tests/test_*.py: on master, collection stops with 6TypeErrorerrors; with this change, the 148 tests of those 6 modules run and pass.pytest tests/test_*.py: same results as on master, plus the new test. On 3.9, withtinkand the Azure SDK installed, the new test fails on master because of the circular import.rulesandoauthbearer-awsmodules also import with stand-ins for their dependencies, which cannot be installed on 3.8.tools/style-format.sh(isort, black, flake8) on the changed files andmypy src/confluent_kafkapass.Open questions / Follow-ups
confluent_kafka.aioon 3.8: the wheel builds only runtests/test_error.py. Addingtests/test_imports.pytoCIBW_TEST_COMMANDwould check every wheel (see also Update wheels CI task to run all unit tests #2303).rulesandoauthbearer-awsextras cannot be installed (cel-python>=0.4.0andboto3>=1.42.25need 3.9+), so neither canrequirements/requirements-tests-install.txt.🤖 Generated with Claude Code
https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN