chore: make mypy happy with webmethod (#1758)

# What does this PR do?
Gets rid of errors like the below, which is on all webmethod decorated
functions
llama_stack/apis/agents/agents.py:398: error: Value of type variable "T"
of function cannot be "Callable[[Agents, AgentConfig], Coroutine[Any,
Any, AgentCreateResponse]]" [type-var]

## Test Plan
Run mypy and observes mypy errors gone
This commit is contained in:
ehhuang 2025-03-22 08:17:23 -07:00 committed by GitHub
parent 06788643b3
commit 39e094736f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,7 +5,7 @@
# the root directory of this source tree.
from dataclasses import dataclass
from typing import Any, Callable, List, Optional, Protocol, TypeVar
from typing import Any, Callable, List, Optional, TypeVar
from .strong_typing.schema import json_schema_type, register_schema # noqa: F401
@ -22,11 +22,7 @@ class WebMethod:
descriptive_name: Optional[str] = None
class HasWebMethod(Protocol):
__webmethod__: WebMethod
T = TypeVar("T", bound=HasWebMethod) # Bound T to classes that match this protocol
T = TypeVar("T", bound=Callable[..., Any])
def webmethod(
@ -47,8 +43,8 @@ def webmethod(
:param response_examples: Sample responses that the operation might produce. Pass a list of objects, not JSON.
"""
def wrap(cls: T) -> T:
cls.__webmethod__ = WebMethod(
def wrap(func: T) -> T:
func.__webmethod__ = WebMethod( # type: ignore
route=route,
method=method,
public=public or False,
@ -57,6 +53,6 @@ def webmethod(
raw_bytes_request_body=raw_bytes_request_body,
descriptive_name=descriptive_name,
)
return cls
return func
return wrap