Skip to content

v0.7.1

Choose a tag to compare

@Lancetnik Lancetnik released this 04 Jun 05:17
5948d1f

What's Changed

TestBroker.aenter was typed to return Broker | list[Broker]. That union is wrong for both usage shapes: mypy rejects .publish() on the single-broker result (the list arm has no such method) and rejects unpacking the multi-broker result (the Broker arm is not iterable).

# Before — both lines fail under `mypy`:
async with TestKafkaBroker(KafkaBroker()) as br:
    await br.publish(None, "test")
    # error: Item "list[KafkaBroker]" of "KafkaBroker | list[KafkaBroker]" has no attribute "publish"  [union-attr]

async with TestKafkaBroker(KafkaBroker(), KafkaBroker()) as (br1, br2):
    # error: "KafkaBroker" object is not iterable  [misc]
    ...

# After — mypy infers the precise type:
async with TestKafkaBroker(KafkaBroker()) as br:
    reveal_type(br)            # KafkaBroker
    await br.publish(None, "test")

async with TestKafkaBroker(KafkaBroker(), KafkaBroker()) as (br1, br2):
    reveal_type(br1)           # tuple[KafkaBroker, ...] -> KafkaBroker
    await br1.publish(None, "test")
    await br2.publish(None, "test")

Full Changelog: 0.7.0...0.7.1