Skip to content

Commit

Permalink
fix Client.publisher
Browse files Browse the repository at this point in the history
* make this method synchronous to use in `async with`
* add Server & Client mypy test cases
  • Loading branch information
zerlok committed Nov 30, 2024
1 parent 0b4e4f3 commit b61e3d3
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "BrokRPC"
version = "0.2.1"
version = "0.2.2"
description = "framework for gRPC like server-client communication over message brokers"
authors = ["zerlok <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion src/brokrpc/rpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Client:
def __init__(self, broker: Broker) -> None:
self.__broker = broker

async def publisher[U](
def publisher[U](
self,
*,
routing_key: str,
Expand Down
96 changes: 96 additions & 0 deletions tests/test_mypy.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,99 @@
- case: server
main: |-
import typing
from brokrpc.abc import Serializer
from brokrpc.message import Message, BinaryMessage
from brokrpc.rpc.abc import RPCSerializer
from brokrpc.rpc.model import Request
from brokrpc.rpc.server import Server
from brokrpc.serializer.json import JSONSerializer
from stubs import *
def main(server: Server, func: {{ func }}, ser: {{ ser }}) -> None:
server.{{ method }}(func=func, routing_key="test", serializer=ser) # {{ expected }}
parametrized:
# positive
- method: register_consumer
func: typing.Callable[[Message[Foo]], None]
ser: Serializer[Message[Foo], BinaryMessage]
expected: Y
- method: register_consumer
func: typing.Callable[[Message[object]], typing.Coroutine[typing.Any, typing.Any, bool]]
ser: JSONSerializer
expected: Y
- method: register_unary_unary_handler
func: typing.Callable[[Request[Foo]], typing.Coroutine[typing.Any, typing.Any, Bar]]
ser: RPCSerializer[Foo, Bar]
expected: Y
- method: register_unary_unary_handler
func: typing.Callable[[Request[object]], object]
ser: JSONSerializer
expected: Y
files:
- path: stubs.py
content: |-
class Foo:
pass
class Bar:
pass
mypy_config: |-
[mypy-aiormq.*,pamqp.*,pkg_resources.*]
ignore_missing_imports = True
ignore_errors = True
- case: client
main: |-
from brokrpc.abc import Serializer
from brokrpc.message import Message, BinaryMessage
from brokrpc.rpc.abc import RPCSerializer
from brokrpc.rpc.client import Client
from brokrpc.serializer.json import JSONSerializer
from stubs import *
async def main(client: Client, ser: {{ ser }}) -> None:
async with client.{{ method }}(routing_key="test", serializer=ser) as caller:
reveal_type(caller) # {{ expected }}
parametrized:
# positive
- method: publisher
ser: Serializer[Message[Foo], BinaryMessage]
expected: |-
N: Revealed type is "brokrpc.abc.Publisher[stubs.Foo, Union[builtins.bool, None]]"
- method: publisher
ser: JSONSerializer
expected: |-
N: Revealed type is "brokrpc.abc.Publisher[builtins.object, Union[builtins.bool, None]]"
- method: unary_unary_caller
ser: RPCSerializer[Foo, Bar]
expected: |-
N: Revealed type is "brokrpc.rpc.abc.Caller[stubs.Foo, stubs.Bar]"
- method: unary_unary_caller
ser: JSONSerializer
expected: |-
N: Revealed type is "brokrpc.rpc.abc.Caller[builtins.object, builtins.object]"
files:
- path: stubs.py
content: |-
class Foo:
pass
class Bar:
pass
mypy_config: |-
[mypy-aiormq.*,pamqp.*,pkg_resources.*]
ignore_missing_imports = True
ignore_errors = True
- case: message_body_covariance
main: |-
from stubs import *
Expand Down

0 comments on commit b61e3d3

Please sign in to comment.