Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0e2aab8
ci
fangnx Nov 6, 2025
d0de972
add types-requests dep
fangnx Nov 6, 2025
221266f
pin boto3
fangnx Nov 10, 2025
446fe83
pin requests
fangnx Nov 10, 2025
76bdee3
pin boto3 for now
fangnx Nov 11, 2025
45983de
pin httpcore
fangnx Nov 11, 2025
b4c6830
pin more to try
fangnx Nov 11, 2025
6147bec
try pip upgrade
fangnx Nov 12, 2025
363f3e5
add constraints back
fangnx Nov 12, 2025
733ca54
upgrade to python 3.11
fangnx Nov 12, 2025
eda5eee
cleanup
fangnx Nov 12, 2025
9744e2e
upgrade semaphore builds to use 3.11
fangnx Nov 12, 2025
35850b2
one new type error
fangnx Nov 12, 2025
214a75c
whitespace
fangnx Nov 12, 2025
916b55f
Resolved conflicts
MSeal Nov 19, 2025
9fc0e05
Resolving setup issues
MSeal Nov 19, 2025
c6ba556
Resolved all type hinting issues locally
MSeal Nov 20, 2025
b1b1798
Merge remote-tracking branch 'origin/master' into mypy-ci
MSeal Nov 20, 2025
9886ed4
Applied unasync
MSeal Nov 20, 2025
8dbe2d0
Resolved mypy failures
MSeal Nov 20, 2025
2c2b09b
Merge remote-tracking branch 'origin/master' into mypy-ci
MSeal Nov 20, 2025
a065646
Merge remote-tracking branch 'origin/master' into mypy-ci
MSeal Nov 20, 2025
b8c0a1b
Flake8 fix plus print for clang-format version
MSeal Nov 20, 2025
45e9a5a
Reverting admin.c to clang-format 18 variant
MSeal Nov 20, 2025
dc88b97
Resolved new avro type checks
MSeal Nov 21, 2025
bba198b
Added mypy ignore for celpy calls
MSeal Nov 21, 2025
e71442a
Upped memory limit as mypy increased the overhead slightly
MSeal Nov 21, 2025
04b1762
Bumped memory for mypy overhead
MSeal Nov 21, 2025
5bc1bc3
Adding file missed in prior commit
MSeal Nov 21, 2025
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
14 changes: 7 additions & 7 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ blocks:
jobs:
- name: Build and Tests with 'classic' group protocol
commands:
- sem-version python 3.9
- sem-version python 3.11
# use a virtualenv
- python3 -m venv _venv && source _venv/bin/activate
- chmod u+r+x tools/source-package-verification.sh
- tools/source-package-verification.sh
- name: Build and Tests with 'consumer' group protocol
commands:
- sem-version python 3.9
- sem-version python 3.11
- sem-version java 17
# use a virtualenv
- python3 -m venv _venv && source _venv/bin/activate
Expand All @@ -213,7 +213,7 @@ blocks:
- tools/source-package-verification.sh
- name: Build, Test, and Report coverage
commands:
- sem-version python 3.9
- sem-version python 3.11
# use a virtualenv
- python3 -m venv _venv && source _venv/bin/activate
- chmod u+r+x tools/source-package-verification.sh
Expand All @@ -237,7 +237,7 @@ blocks:
jobs:
- name: Build
commands:
- sem-version python 3.9
- sem-version python 3.11
# use a virtualenv
- python3 -m venv _venv && source _venv/bin/activate
- chmod u+r+x tools/source-package-verification.sh
Expand All @@ -256,7 +256,7 @@ blocks:
jobs:
- name: Build
commands:
- sem-version python 3.9
- sem-version python 3.11
# use a virtualenv
- python3 -m venv _venv && source _venv/bin/activate
- chmod u+r+x tools/source-package-verification.sh
Expand All @@ -275,7 +275,7 @@ blocks:
jobs:
- name: Build
commands:
- sem-version python 3.9
- sem-version python 3.11
# use a virtualenv
- python3 -m venv _venv && source _venv/bin/activate
- chmod u+r+x tools/source-package-verification.sh
Expand All @@ -302,7 +302,7 @@ blocks:
- name: Build and Tests
commands:
# Setup Python environment
- sem-version python 3.9
- sem-version python 3.11
- python3 -m venv _venv && source _venv/bin/activate

# Install ducktape framework and additional dependencies
Expand Down
5 changes: 4 additions & 1 deletion DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,11 @@ tox -e black,isort
# Check linting
tox -e flake8
# Check typing
tox -e mypy
# Run all formatting and linting checks
tox -e black,isort,flake8
tox -e black,isort,flake8,mypy
```
## Documentation build
Expand Down
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include README.md
include LICENSE
include src/confluent_kafka/src/*.[ch]
include src/confluent_kafka/py.typed
include src/confluent_kafka/cimpl.pyi
prune tests
prune docs
prune docs
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ all:
@echo "Targets:"
@echo " clean"
@echo " docs"
@echo " mypy"
@echo " style-check"
@echo " style-fix"


clean:
Expand All @@ -14,6 +17,9 @@ clean:
docs:
$(MAKE) -C docs html

mypy:
python3 -m mypy src/confluent_kafka

style-check:
@(tools/style-format.sh \
$$(git ls-tree -r --name-only HEAD | egrep '\.(c|h|py)$$') )
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-avro.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fastavro < 1.8.0; python_version == "3.7"
fastavro < 2; python_version > "3.7"
requests
avro>=1.11.1,<2
avro>=1.11.1,<2
2 changes: 2 additions & 0 deletions requirements/requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
urllib3<3
flake8
mypy
attrs
types-cachetools
types-requests
orjson
pytest
pytest-timeout
Expand Down
6 changes: 5 additions & 1 deletion src/confluent_kafka/deserializing_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ def poll(self, timeout: float = -1) -> Optional[Message]:
if error is not None:
raise ConsumeError(error, kafka_message=msg)

ctx = SerializationContext(msg.topic(), MessageField.VALUE, msg.headers())
topic = msg.topic()
if topic is None:
raise TypeError("Message topic is None")
ctx = SerializationContext(topic, MessageField.VALUE, msg.headers())

value = msg.value()
if self._value_deserializer is not None:
try:
Expand Down
16 changes: 11 additions & 5 deletions src/confluent_kafka/schema_registry/common/avro.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import defaultdict
from copy import deepcopy
from io import BytesIO
from typing import Dict, Optional, Set, Tuple, Union
from typing import Dict, Optional, Set, Tuple, Union, cast

from fastavro import repository, validate
from fastavro.schema import load_schema
Expand Down Expand Up @@ -217,11 +217,17 @@ def _resolve_union(schema: AvroSchema, message: AvroMessage) -> Tuple[Optional[A
for subschema in schema:
try:
if is_wrapped_union:
if isinstance(subschema, dict) and subschema["name"] == message[0]:
return (subschema, message[1])
if isinstance(subschema, dict):
dict_schema = cast(dict, subschema)
tuple_message = cast(tuple, message)
if dict_schema["name"] == tuple_message[0]:
return (dict_schema, tuple_message[1])
elif is_typed_union:
if isinstance(subschema, dict) and subschema["name"] == message['-type']:
return (subschema, message)
if isinstance(subschema, dict):
dict_schema = cast(dict, subschema)
dict_message = cast(dict, message)
if dict_schema["name"] == dict_message['-type']:
return (dict_schema, dict_message)
else:
validate(message, subschema)
return (subschema, message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def __init__(self, locale: str):
def format(self, fmt: celtypes.Value, args: celtypes.Value) -> celpy.Result:
if not isinstance(fmt, celtypes.StringType):
return celpy.native_to_cel( # type: ignore[attr-defined]
celpy.new_error("format() requires a string as the first argument")
celpy.new_error("format() requires a string as the first argument") # type: ignore[attr-defined]
) # type: ignore[attr-defined]
if not isinstance(args, celtypes.ListType):
return celpy.native_to_cel( # type: ignore[attr-defined]
celpy.new_error("format() requires a list as the second argument")
celpy.new_error("format() requires a list as the second argument") # type: ignore[attr-defined]
) # type: ignore[attr-defined]
# printf style formatting
i = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def _is_expired(self, ctx: RuleContext, dek: Optional[Dek]) -> bool:
ctx.rule_mode != RuleMode.READ
and self._dek_expiry_days > 0
and dek is not None
and (now - dek.ts) / MILLIS_IN_DAY > self._dek_expiry_days
and (now - (dek.ts or 0)) / MILLIS_IN_DAY > self._dek_expiry_days
) # type: ignore[operator]

def transform(self, ctx: RuleContext, field_type: FieldType, field_value: Any) -> Any:
Expand Down
4 changes: 2 additions & 2 deletions tests/ducktape/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The bounds configuration supports different environments with different performa
"max_error_rate": 0.02,
"min_success_rate": 0.98,
"max_p99_latency_ms": 3000.0,
"max_memory_growth_mb": 800.0,
"max_memory_growth_mb": 1000.0,
"max_buffer_full_rate": 0.05,
"min_messages_per_poll": 10.0
},
Expand All @@ -62,7 +62,7 @@ The bounds configuration supports different environments with different performa
"max_error_rate": 0.01,
"min_success_rate": 0.99,
"max_p99_latency_ms": 2500.0,
"max_memory_growth_mb": 600.0,
"max_memory_growth_mb": 700.0,
"max_buffer_full_rate": 0.03,
"min_messages_per_poll": 15.0
},
Expand Down
2 changes: 1 addition & 1 deletion tests/ducktape/consumer_benchmark_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def __init__(
max_p95_latency_ms: float = 10000.0,
min_success_rate: float = 0.90,
max_error_rate: float = 0.05,
max_memory_growth_mb: float = 600.0,
max_memory_growth_mb: float = 700.0,
min_messages_per_consume: float = 0.5,
max_empty_consume_rate: float = 0.5,
):
Expand Down
4 changes: 2 additions & 2 deletions tests/ducktape/producer_benchmark_bounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"max_error_rate": 0.02,
"min_success_rate": 0.98,
"max_p99_latency_ms": 7000.0,
"max_memory_growth_mb": 800.0,
"max_memory_growth_mb": 1000.0,
"max_buffer_full_rate": 0.05,
"min_messages_per_poll": 5.0
},
Expand All @@ -18,7 +18,7 @@
"max_error_rate": 0.01,
"min_success_rate": 0.99,
"max_p99_latency_ms": 12000.0,
"max_memory_growth_mb": 800.0,
"max_memory_growth_mb": 1000.0,
"max_buffer_full_rate": 0.03,
"min_messages_per_poll": 5.0
},
Expand Down
4 changes: 2 additions & 2 deletions tests/ducktape/run_ducktape_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def run_all_tests(args):
print("=" * 70)

for test_type in test_types:
print(f"\n{'='*20} Running {test_type.upper()} Tests {'='*20}")
print(f"\n{'='*20} Running {test_type.upper()} Tests {'='*20}") # noqa: E226

# Create a new args object for this test type
test_args = argparse.Namespace(test_type=test_type, test_method=args.test_method, debug=args.debug)
Expand All @@ -148,7 +148,7 @@ def run_all_tests(args):
else:
print(f"\n✅ {test_type.upper()} tests passed!")

print(f"\n{'='*70}")
print(f"\n{'='*70}") # noqa: E226
if overall_success:
print("🎉 All tests completed successfully!")
return 0
Expand Down
4 changes: 2 additions & 2 deletions tests/ducktape/transaction_benchmark_bounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"max_error_rate": 0.02,
"min_success_rate": 0.98,
"max_p99_latency_ms": 8000.0,
"max_memory_growth_mb": 800.0,
"max_memory_growth_mb": 1000.0,
"max_buffer_full_rate": 0.05,
"min_messages_per_poll": 0.0
},
Expand All @@ -18,7 +18,7 @@
"max_error_rate": 0.01,
"min_success_rate": 0.99,
"max_p99_latency_ms": 7000.0,
"max_memory_growth_mb": 600.0,
"max_memory_growth_mb": 700.0,
"max_buffer_full_rate": 0.03,
"min_messages_per_poll": 0.0
},
Expand Down
6 changes: 6 additions & 0 deletions tools/source-package-verification.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
set -e

pip install --upgrade pip
pip install -r requirements/requirements-tests-install.txt
pip install -U build

Expand Down Expand Up @@ -52,9 +53,14 @@ if [[ $OS_NAME == linux && $ARCH == x64 ]]; then
echo "Checking code formatting ..."
# Check all tracked files (Python and C)
all_files=$(git ls-tree -r --name-only HEAD | egrep '\.(py|c|h)$')
clang-format --version
tools/style-format.sh $all_files || exit 1
echo "Building documentation ..."
flake8 --exclude ./_venv,*_pb2.py,./build

echo "Running mypy type checking ..."
python3.11 -m mypy src/confluent_kafka

pip install -r requirements/requirements-docs.txt
make docs

Expand Down
12 changes: 11 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = flake8,black,isort,py37,py38,py39,py310,py311,py312,py313
envlist = flake8,black,isort,mypy,py37,py38,py39,py310,py311,py312,py313

[testenv]
passenv =
Expand All @@ -20,6 +20,16 @@ commands =
deps = flake8
commands = flake8

[testenv:mypy]
deps =
mypy
types-cachetools
types-requests~=2.32.0
commands =
# Need attrs to be explicitly installed for mypy to find frozen class init definitions
pip install attrs
mypy src/confluent_kafka

[testenv:black]
deps = black>=24.0.0
commands = black --check --diff .
Expand Down