Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHIA-1692 Annotate chia/rpc/util.py #18798

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 17 additions & 9 deletions chia/rpc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
# This definition is weaker than that one however because the arguments can be anything
RpcEndpoint = Callable[..., Awaitable[dict[str, Any]]]
MarshallableRpcEndpoint = Callable[..., Awaitable[Streamable]]
if TYPE_CHECKING:
from chia.rpc.rpc_server import EndpointResult
from chia.rpc.wallet_rpc_api import WalletRpcApi
else:
EndpointResult = dict[str, Any]
WalletRpcApi = object


ALL_TRANSLATION_LAYERS: dict[str, TranslationLayer] = {"CHIP-0028": BLIND_SIGNER_TRANSLATION}
Expand All @@ -45,7 +51,9 @@ def marshal(func: MarshallableRpcEndpoint) -> RpcEndpoint:
assert issubclass(request_hint, Streamable)
request_class = request_hint

async def rpc_endpoint(self, request: dict[str, Any], *args: object, **kwargs: object) -> dict[str, Any]:
async def rpc_endpoint(
self: WalletRpcApi, request: dict[str, Any], *args: object, **kwargs: object
) -> EndpointResult:
response_obj: Streamable = await func(
self,
(
Expand Down Expand Up @@ -78,8 +86,10 @@ async def rpc_endpoint(self, request: dict[str, Any], *args: object, **kwargs: o
return rpc_endpoint


def wrap_http_handler(f) -> Callable:
async def inner(request) -> aiohttp.web.Response:
def wrap_http_handler(
f: Callable[[dict[str, Any]], Awaitable[EndpointResult]]
) -> Callable[[aiohttp.web.Request], Awaitable[aiohttp.web.StreamResponse]]:
async def inner(request: aiohttp.web.Request) -> aiohttp.web.StreamResponse:
request_data = await request.json()
try:
res_object = await f(request_data)
Expand All @@ -105,11 +115,9 @@ def tx_endpoint(
merge_spends: bool = True,
) -> Callable[[RpcEndpoint], RpcEndpoint]:
def _inner(func: RpcEndpoint) -> RpcEndpoint:
async def rpc_endpoint(self, request: dict[str, Any], *args, **kwargs) -> dict[str, Any]:
if TYPE_CHECKING:
from chia.rpc.wallet_rpc_api import WalletRpcApi

assert isinstance(self, WalletRpcApi)
async def rpc_endpoint(
self: WalletRpcApi, request: dict[str, Any], *args: object, **kwargs: object
) -> EndpointResult:
assert self.service.logged_in_fingerprint is not None
tx_config_loader: TXConfigLoader = TXConfigLoader.from_json_dict(request)

Expand Down Expand Up @@ -157,7 +165,7 @@ async def rpc_endpoint(self, request: dict[str, Any], *args, **kwargs) -> dict[s
merge_spends=request.get("merge_spends", merge_spends),
sign=request.get("sign", self.service.config.get("auto_sign_txs", True)),
) as action_scope:
response: dict[str, Any] = await func(
response: EndpointResult = await func(
self,
request,
*args,
Expand Down
1 change: 0 additions & 1 deletion mypy-exclusions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ chia.plotters.plotters_util
chia.plotting.manager
chia.plotting.util
chia.rpc.rpc_client
chia.rpc.util
chia.simulator.full_node_simulator
chia.simulator.keyring
chia.simulator.wallet_tools
Expand Down
Loading