Add strict mode to pyright (#315)
* Add strict mode to pyright * Apply UP rule * fix readme * More correct * Leave wrong Context for now * Add strict mode to pyright * Apply UP rule * fix readme * fix * ignore
This commit is contained in:
parent
5a54d82459
commit
ae77772ea8
1 changed files with 194 additions and 133 deletions
|
|
@ -1,10 +1,19 @@
|
|||
from collections.abc import Generator
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Generic
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from mcp.shared.context import RequestContext
|
||||
from mcp.shared.session import BaseSession
|
||||
from mcp.shared.session import (
|
||||
BaseSession,
|
||||
ReceiveNotificationT,
|
||||
ReceiveRequestT,
|
||||
SendNotificationT,
|
||||
SendRequestT,
|
||||
SendResultT,
|
||||
)
|
||||
from mcp.types import ProgressToken
|
||||
|
||||
|
||||
|
|
@ -14,8 +23,22 @@ class Progress(BaseModel):
|
|||
|
||||
|
||||
@dataclass
|
||||
class ProgressContext:
|
||||
session: BaseSession
|
||||
class ProgressContext(
|
||||
Generic[
|
||||
SendRequestT,
|
||||
SendNotificationT,
|
||||
SendResultT,
|
||||
ReceiveRequestT,
|
||||
ReceiveNotificationT,
|
||||
]
|
||||
):
|
||||
session: BaseSession[
|
||||
SendRequestT,
|
||||
SendNotificationT,
|
||||
SendResultT,
|
||||
ReceiveRequestT,
|
||||
ReceiveNotificationT,
|
||||
]
|
||||
progress_token: ProgressToken
|
||||
total: float | None
|
||||
current: float = field(default=0.0, init=False)
|
||||
|
|
@ -29,7 +52,27 @@ class ProgressContext:
|
|||
|
||||
|
||||
@contextmanager
|
||||
def progress(ctx: RequestContext, total: float | None = None):
|
||||
def progress(
|
||||
ctx: RequestContext[
|
||||
BaseSession[
|
||||
SendRequestT,
|
||||
SendNotificationT,
|
||||
SendResultT,
|
||||
ReceiveRequestT,
|
||||
ReceiveNotificationT,
|
||||
]
|
||||
],
|
||||
total: float | None = None,
|
||||
) -> Generator[
|
||||
ProgressContext[
|
||||
SendRequestT,
|
||||
SendNotificationT,
|
||||
SendResultT,
|
||||
ReceiveRequestT,
|
||||
ReceiveNotificationT,
|
||||
],
|
||||
None,
|
||||
]:
|
||||
if ctx.meta is None or ctx.meta.progressToken is None:
|
||||
raise ValueError("No progress token provided")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue