From b3e295e735ccf8b1e78f55725e5aa54a2352f3f6 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 20 Nov 2025 16:58:16 +0800 Subject: [PATCH 1/2] fix: use classmethod for error factory methods Signed-off-by: Frost Ming --- pyproject.toml | 2 +- src/acp/exceptions.py | 44 +++++++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2fc88b3..4ad791a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ description = "A Python implement of Agent Client Protocol (ACP, by Zed Industri authors = [{ name = "Chojan Shang", email = "psiace@apache.org" }] readme = "README.md" keywords = ['python'] -requires-python = ">=3.10,<=3.14" +requires-python = ">=3.10,<3.15" classifiers = [ "Intended Audience :: Developers", "Programming Language :: Python", diff --git a/src/acp/exceptions.py b/src/acp/exceptions.py index 898ca40..ce63072 100644 --- a/src/acp/exceptions.py +++ b/src/acp/exceptions.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any +from typing import Any, Self __all__ = ["RequestError"] @@ -13,34 +13,34 @@ def __init__(self, code: int, message: str, data: Any | None = None) -> None: self.code = code self.data = data - @staticmethod - def parse_error(data: dict[str, Any] | None = None) -> RequestError: - return RequestError(-32700, "Parse error", data) + @classmethod + def parse_error(cls, data: dict[str, Any] | None = None) -> Self: + return cls(-32700, "Parse error", data) - @staticmethod - def invalid_request(data: dict[str, Any] | None = None) -> RequestError: - return RequestError(-32600, "Invalid request", data) + @classmethod + def invalid_request(cls, data: dict[str, Any] | None = None) -> Self: + return cls(-32600, "Invalid request", data) - @staticmethod - def method_not_found(method: str) -> RequestError: - return RequestError(-32601, "Method not found", {"method": method}) + @classmethod + def method_not_found(cls, method: str) -> Self: + return cls(-32601, "Method not found", {"method": method}) - @staticmethod - def invalid_params(data: dict[str, Any] | None = None) -> RequestError: - return RequestError(-32602, "Invalid params", data) + @classmethod + def invalid_params(cls, data: dict[str, Any] | None = None) -> Self: + return cls(-32602, "Invalid params", data) - @staticmethod - def internal_error(data: dict[str, Any] | None = None) -> RequestError: - return RequestError(-32603, "Internal error", data) + @classmethod + def internal_error(cls, data: dict[str, Any] | None = None) -> Self: + return cls(-32603, "Internal error", data) - @staticmethod - def auth_required(data: dict[str, Any] | None = None) -> RequestError: - return RequestError(-32000, "Authentication required", data) + @classmethod + def auth_required(cls, data: dict[str, Any] | None = None) -> Self: + return cls(-32000, "Authentication required", data) - @staticmethod - def resource_not_found(uri: str | None = None) -> RequestError: + @classmethod + def resource_not_found(cls, uri: str | None = None) -> Self: data = {"uri": uri} if uri is not None else None - return RequestError(-32002, "Resource not found", data) + return cls(-32002, "Resource not found", data) def to_error_obj(self) -> dict[str, Any]: return {"code": self.code, "message": str(self), "data": self.data} From a48f3b54a166c69db8574322e96c2349168356e6 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 20 Nov 2025 18:02:02 +0800 Subject: [PATCH 2/2] fix: update return type hints for RequestError factory methods Signed-off-by: Frost Ming --- src/acp/exceptions.py | 16 ++++++++-------- uv.lock | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/acp/exceptions.py b/src/acp/exceptions.py index ce63072..06098dd 100644 --- a/src/acp/exceptions.py +++ b/src/acp/exceptions.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, Self +from typing import Any __all__ = ["RequestError"] @@ -14,31 +14,31 @@ def __init__(self, code: int, message: str, data: Any | None = None) -> None: self.data = data @classmethod - def parse_error(cls, data: dict[str, Any] | None = None) -> Self: + def parse_error(cls, data: dict[str, Any] | None = None) -> RequestError: return cls(-32700, "Parse error", data) @classmethod - def invalid_request(cls, data: dict[str, Any] | None = None) -> Self: + def invalid_request(cls, data: dict[str, Any] | None = None) -> RequestError: return cls(-32600, "Invalid request", data) @classmethod - def method_not_found(cls, method: str) -> Self: + def method_not_found(cls, method: str) -> RequestError: return cls(-32601, "Method not found", {"method": method}) @classmethod - def invalid_params(cls, data: dict[str, Any] | None = None) -> Self: + def invalid_params(cls, data: dict[str, Any] | None = None) -> RequestError: return cls(-32602, "Invalid params", data) @classmethod - def internal_error(cls, data: dict[str, Any] | None = None) -> Self: + def internal_error(cls, data: dict[str, Any] | None = None) -> RequestError: return cls(-32603, "Internal error", data) @classmethod - def auth_required(cls, data: dict[str, Any] | None = None) -> Self: + def auth_required(cls, data: dict[str, Any] | None = None) -> RequestError: return cls(-32000, "Authentication required", data) @classmethod - def resource_not_found(cls, uri: str | None = None) -> Self: + def resource_not_found(cls, uri: str | None = None) -> RequestError: data = {"uri": uri} if uri is not None else None return cls(-32002, "Resource not found", data) diff --git a/uv.lock b/uv.lock index 4c6b491..10967c7 100644 --- a/uv.lock +++ b/uv.lock @@ -1,6 +1,6 @@ version = 1 revision = 3 -requires-python = ">=3.10, <=3.14" +requires-python = ">=3.10, <3.15" [[package]] name = "agent-client-protocol"