Skip to content

Commit

Permalink
Test generic message type variance in Senders and Receivers
Browse files Browse the repository at this point in the history
  • Loading branch information
shsms committed Jan 9, 2024
1 parent 05c517c commit 179f830
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


import asyncio
from dataclasses import dataclass

import pytest

Expand Down Expand Up @@ -252,3 +253,27 @@ async def test_broadcast_receiver_drop() -> None:

assert len(chan._receivers) == 1
# pylint: enable=protected-access


async def test_type_variance() -> None:
"""Ensure that the type variance of Broadcast is working."""

@dataclass
class Broader:
"""A broad class."""

value: int

class Actual(Broader):
"""Actual class."""

class Narrower(Actual):
"""A narrower class."""

chan = Broadcast[Actual](name="input-chan")

sender: Sender[Narrower] = chan.new_sender()
receiver: Receiver[Broader] = chan.new_receiver()

await sender.send(Narrower(10))
assert (await receiver.receive()).value == 10

0 comments on commit 179f830

Please sign in to comment.