Skip to content

Commit 8556f0d

Browse files
authored
fix: use classmethod for error factory methods (#40)
* fix: use classmethod for error factory methods Signed-off-by: Frost Ming <[email protected]> * fix: update return type hints for RequestError factory methods Signed-off-by: Frost Ming <[email protected]> --------- Signed-off-by: Frost Ming <[email protected]>
1 parent 755a8ca commit 8556f0d

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "A Python implement of Agent Client Protocol (ACP, by Zed Industri
55
authors = [{ name = "Chojan Shang", email = "[email protected]" }]
66
readme = "README.md"
77
keywords = ['python']
8-
requires-python = ">=3.10,<=3.14"
8+
requires-python = ">=3.10,<3.15"
99
classifiers = [
1010
"Intended Audience :: Developers",
1111
"Programming Language :: Python",

src/acp/exceptions.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@ def __init__(self, code: int, message: str, data: Any | None = None) -> None:
1313
self.code = code
1414
self.data = data
1515

16-
@staticmethod
17-
def parse_error(data: dict[str, Any] | None = None) -> RequestError:
18-
return RequestError(-32700, "Parse error", data)
16+
@classmethod
17+
def parse_error(cls, data: dict[str, Any] | None = None) -> RequestError:
18+
return cls(-32700, "Parse error", data)
1919

20-
@staticmethod
21-
def invalid_request(data: dict[str, Any] | None = None) -> RequestError:
22-
return RequestError(-32600, "Invalid request", data)
20+
@classmethod
21+
def invalid_request(cls, data: dict[str, Any] | None = None) -> RequestError:
22+
return cls(-32600, "Invalid request", data)
2323

24-
@staticmethod
25-
def method_not_found(method: str) -> RequestError:
26-
return RequestError(-32601, "Method not found", {"method": method})
24+
@classmethod
25+
def method_not_found(cls, method: str) -> RequestError:
26+
return cls(-32601, "Method not found", {"method": method})
2727

28-
@staticmethod
29-
def invalid_params(data: dict[str, Any] | None = None) -> RequestError:
30-
return RequestError(-32602, "Invalid params", data)
28+
@classmethod
29+
def invalid_params(cls, data: dict[str, Any] | None = None) -> RequestError:
30+
return cls(-32602, "Invalid params", data)
3131

32-
@staticmethod
33-
def internal_error(data: dict[str, Any] | None = None) -> RequestError:
34-
return RequestError(-32603, "Internal error", data)
32+
@classmethod
33+
def internal_error(cls, data: dict[str, Any] | None = None) -> RequestError:
34+
return cls(-32603, "Internal error", data)
3535

36-
@staticmethod
37-
def auth_required(data: dict[str, Any] | None = None) -> RequestError:
38-
return RequestError(-32000, "Authentication required", data)
36+
@classmethod
37+
def auth_required(cls, data: dict[str, Any] | None = None) -> RequestError:
38+
return cls(-32000, "Authentication required", data)
3939

40-
@staticmethod
41-
def resource_not_found(uri: str | None = None) -> RequestError:
40+
@classmethod
41+
def resource_not_found(cls, uri: str | None = None) -> RequestError:
4242
data = {"uri": uri} if uri is not None else None
43-
return RequestError(-32002, "Resource not found", data)
43+
return cls(-32002, "Resource not found", data)
4444

4545
def to_error_obj(self) -> dict[str, Any]:
4646
return {"code": self.code, "message": str(self), "data": self.data}

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)