Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ jobs:
git diff --exit-code
- name: Formatting check
run: uv run --frozen ruff format --check
- name: Typing check
run: uv run --frozen ty check
34 changes: 24 additions & 10 deletions packages/bot/src/automa/bot/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
Iterator,
TypeVar,
Union,
cast,
)

from httpx import URL, AsyncClient, Client, Response
from httpx._types import HeaderTypes

from ._types import Headers, RequestOptions
from ._types import RequestOptions

_T = TypeVar("_T")

Expand Down Expand Up @@ -48,7 +50,7 @@ def base_url(self, url: str | URL) -> None:
)

@property
def default_headers(self) -> Headers:
def default_headers(self) -> HeaderTypes:
return {
"Accept": "application/json",
"Content-Type": "application/json",
Expand Down Expand Up @@ -109,7 +111,7 @@ def get(
self,
path: str,
*,
options: RequestOptions = {},
options: RequestOptions = cast(RequestOptions, {}),
) -> Response:
return self.method("get", path, options=options)

Expand All @@ -118,7 +120,7 @@ def post(
path: str,
*,
body: Any | None = None,
options: RequestOptions = {},
options: RequestOptions = cast(RequestOptions, {}),
) -> Response:
return self.method(
"post",
Expand All @@ -130,7 +132,11 @@ def post(
)

def method(
self, method: str, path: str, *, options: RequestOptions = {}
self,
method: str,
path: str,
*,
options: RequestOptions = cast(RequestOptions, {}),
) -> Response:
options["headers"] = {**self.default_headers, **options.get("headers", {})}

Expand All @@ -144,7 +150,11 @@ def method(

@contextmanager
def stream(
self, method: str, path: str, *, options: RequestOptions = {}
self,
method: str,
path: str,
*,
options: RequestOptions = cast(RequestOptions, {}),
) -> Iterator[Response]:
options["headers"] = {**self.default_headers, **options.get("headers", {})}

Expand Down Expand Up @@ -208,7 +218,7 @@ async def get(
self,
path: str,
*,
options: RequestOptions = {},
options: RequestOptions = cast(RequestOptions, {}),
) -> Response:
return await self.method("get", path, options=options)

Expand All @@ -217,7 +227,7 @@ async def post(
path: str,
*,
body: Any | None = None,
options: RequestOptions = {},
options: RequestOptions = cast(RequestOptions, {}),
) -> Response:
return await self.method(
"post",
Expand All @@ -233,7 +243,7 @@ async def method(
method: str,
path: str,
*,
options: RequestOptions = {},
options: RequestOptions = cast(RequestOptions, {}),
) -> Response:
options["headers"] = {**self.default_headers, **options.get("headers", {})}

Expand All @@ -247,7 +257,11 @@ async def method(

@asynccontextmanager
async def stream(
self, method: str, path: str, *, options: RequestOptions = {}
self,
method: str,
path: str,
*,
options: RequestOptions = cast(RequestOptions, {}),
) -> AsyncIterator[Response]:
options["headers"] = {**self.default_headers, **options.get("headers", {})}

Expand Down
12 changes: 6 additions & 6 deletions packages/bot/src/automa/bot/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import os

from httpx import URL
from httpx._types import HeaderTypes
from typing_extensions import override

from ._base_client import (
AsyncAPIClient,
Headers,
SyncAPIClient,
)
from .resources import code
Expand All @@ -19,15 +19,15 @@


class Automa(SyncAPIClient):
_default_headers: Headers
_default_headers: HeaderTypes

code: code.CodeResource

def __init__(
self,
*,
base_url: str | URL | None = None,
default_headers: Headers | None = None,
default_headers: HeaderTypes | None = None,
) -> None:
"""Construct a new synchronous Automa client instance."""
if base_url is None:
Expand All @@ -53,15 +53,15 @@ def default_headers(self) -> dict[str, str]:


class AsyncAutoma(AsyncAPIClient):
_default_headers: Headers
_default_headers: HeaderTypes

code: code.AsyncCodeResource

def __init__(
self,
*,
base_url: str | URL | None = None,
default_headers: Headers | None = None,
default_headers: HeaderTypes | None = None,
) -> None:
"""Construct a new async AsyncAutoma client instance."""
if base_url is None:
Expand All @@ -79,7 +79,7 @@ def __init__(

@property
@override
def default_headers(self) -> Headers:
def default_headers(self) -> HeaderTypes:
return {
**super().default_headers,
**self._default_headers,
Expand Down
10 changes: 3 additions & 7 deletions packages/bot/src/automa/bot/_types.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

from enum import Enum
from typing import Any, Dict, Literal, Mapping, NotRequired, TypedDict, Union
from typing import Any, Dict, Literal, NotRequired, TypedDict, Union

from httpx._types import QueryParamTypes, RequestExtensions
from httpx._types import HeaderTypes, QueryParamTypes, RequestExtensions


class Omit:
Expand All @@ -27,15 +27,11 @@ def __bool__(self) -> Literal[False]:
return False


Headers = Mapping[str, Union[str, Omit]]


class RequestOptions(TypedDict, total=False):
json: Any | None
headers: Headers | None
headers: HeaderTypes | None
params: QueryParamTypes | None
extensions: RequestExtensions | None
stream: bool | None


class ProposalTaskItem(TypedDict):
Expand Down
26 changes: 21 additions & 5 deletions packages/bot/src/automa/bot/resources/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from os.path import join
from pathlib import Path
from shutil import rmtree
from typing import NotRequired, TypedDict
from typing import NotRequired, TypedDict, cast

from .._resource import AsyncAPIResource, SyncAPIResource
from .._types import RequestOptions
Expand Down Expand Up @@ -146,7 +146,10 @@ def cleanup(self, body: CodeCleanupParams) -> None:
pass

def download(
self, body: CodeDownloadParams, *, options: RequestOptions = {}
self,
body: CodeDownloadParams,
*,
options: RequestOptions = cast(RequestOptions, {}),
) -> CodeFolder:
token = None
path = self._path(body["task"])
Expand Down Expand Up @@ -191,7 +194,12 @@ def download(

return CodeFolder(path)

def propose(self, body: CodeProposeParams, *, options: RequestOptions = {}):
def propose(
self,
body: CodeProposeParams,
*,
options: RequestOptions = cast(RequestOptions, {}),
):
path = self._path(body["task"])
token = self._read_token(path)
base_commit = self._read_base_commit(path)
Expand Down Expand Up @@ -228,7 +236,10 @@ async def cleanup(self, body: CodeCleanupParams) -> None:
pass

async def download(
self, body: CodeDownloadParams, *, options: RequestOptions = {}
self,
body: CodeDownloadParams,
*,
options: RequestOptions = cast(RequestOptions, {}),
) -> CodeFolder:
token = None
path = self._path(body["task"])
Expand Down Expand Up @@ -276,7 +287,12 @@ async def download(

return CodeFolder(path)

async def propose(self, body: CodeProposeParams, *, options: RequestOptions = {}):
async def propose(
self,
body: CodeProposeParams,
*,
options: RequestOptions = cast(RequestOptions, {}),
):
path = self._path(body["task"])
token = await to_thread(self._read_token, path)
base_commit = await to_thread(self._read_base_commit, path)
Expand Down
4 changes: 2 additions & 2 deletions packages/bot/tests/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def test_returns_false_if_secret_is_not_a_string():
result = verify_webhook(1, "signature", "{}")
result = verify_webhook(1, "signature", "{}") # ty:ignore[invalid-argument-type]

assert result is False

Expand All @@ -14,7 +14,7 @@ def test_returns_false_if_secret_is_empty():


def test_returns_false_if_signature_is_not_a_string():
result = verify_webhook("secret", 1, "{}")
result = verify_webhook("secret", 1, "{}") # ty:ignore[invalid-argument-type]

assert result is False

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = ["packages/bot"]

[dependency-groups]
dev = ["pytest-asyncio~=0.26.0", "pytest-cov~=6.0.0", "pytest~=8.3.5", "ruff~=0.9"]
dev = ["pytest-asyncio~=0.26.0", "pytest-cov~=6.0.0", "pytest~=8.3.5", "ruff~=0.9", "ty~=0.0.8"]

[tool.pytest.ini_options]
asyncio_default_fixture_loop_scope = "function"
26 changes: 26 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.