mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-06-27 18:50:41 +00:00
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:
parent
06788643b3
commit
39e094736f
1 changed files with 5 additions and 9 deletions
|
@ -5,7 +5,7 @@
|
||||||
# the root directory of this source tree.
|
# the root directory of this source tree.
|
||||||
|
|
||||||
from dataclasses import dataclass
|
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
|
from .strong_typing.schema import json_schema_type, register_schema # noqa: F401
|
||||||
|
|
||||||
|
@ -22,11 +22,7 @@ class WebMethod:
|
||||||
descriptive_name: Optional[str] = None
|
descriptive_name: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class HasWebMethod(Protocol):
|
T = TypeVar("T", bound=Callable[..., Any])
|
||||||
__webmethod__: WebMethod
|
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar("T", bound=HasWebMethod) # Bound T to classes that match this protocol
|
|
||||||
|
|
||||||
|
|
||||||
def webmethod(
|
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.
|
:param response_examples: Sample responses that the operation might produce. Pass a list of objects, not JSON.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def wrap(cls: T) -> T:
|
def wrap(func: T) -> T:
|
||||||
cls.__webmethod__ = WebMethod(
|
func.__webmethod__ = WebMethod( # type: ignore
|
||||||
route=route,
|
route=route,
|
||||||
method=method,
|
method=method,
|
||||||
public=public or False,
|
public=public or False,
|
||||||
|
@ -57,6 +53,6 @@ def webmethod(
|
||||||
raw_bytes_request_body=raw_bytes_request_body,
|
raw_bytes_request_body=raw_bytes_request_body,
|
||||||
descriptive_name=descriptive_name,
|
descriptive_name=descriptive_name,
|
||||||
)
|
)
|
||||||
return cls
|
return func
|
||||||
|
|
||||||
return wrap
|
return wrap
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue