Skip to content

Commit b596e71

Browse files
committed
Update tests, pass CI
1 parent 34d932f commit b596e71

23 files changed

Lines changed: 159 additions & 139 deletions

scripts/generate_examples_md.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
import re
1212
import sys
1313
import argparse
14-
from typing import Any
14+
from typing import Any, cast
1515
from pathlib import Path
1616

17-
import frontmatter # type: ignore[import-untyped]
17+
import frontmatter # type: ignore[import-not-found, import-untyped]
1818

1919
ROOT = Path(__file__).parent.parent
2020
EXAMPLES_DIR = ROOT / "examples"
@@ -38,7 +38,7 @@ def parse_example(path: Path) -> dict[str, Any]:
3838
raise ValueError(f"{path}: docstring must start with frontmatter (---)")
3939

4040
try:
41-
post = frontmatter.loads(docstring)
41+
post = cast(Any, frontmatter).loads(docstring)
4242
return dict(post.metadata)
4343
except Exception as e:
4444
raise ValueError(f"{path}: invalid frontmatter: {e}") from e

src/runloop_api_client/_utils/_compat.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import sys
44
import typing_extensions
5-
from typing import Any, Type, Union, Literal, Optional
5+
from typing import Any, Type, Union, Literal, Optional, cast
66
from datetime import date, datetime
77
from typing_extensions import get_args as _get_args, get_origin as _get_origin
88

@@ -34,7 +34,8 @@ def is_typeddict(tp: Type[Any]) -> bool:
3434

3535

3636
def is_literal_type(tp: Type[Any]) -> bool:
37-
return get_origin(tp) in _LITERAL_TYPES
37+
origin = get_origin(tp)
38+
return cast(Any, origin) in _LITERAL_TYPES
3839

3940

4041
def parse_date(value: Union[date, StrBytesIntFloat]) -> date:

src/runloop_api_client/_utils/_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ def file_from_path(path: str) -> FileTypes:
372372
def get_required_header(headers: HeadersLike, header: str) -> str:
373373
lower_header = header.lower()
374374
if is_mapping_t(headers):
375-
# mypy doesn't understand the type narrowing here
376-
for k, v in headers.items(): # type: ignore
375+
for k, v in cast(Mapping[str, object], headers).items():
377376
if k.lower() == lower_header and isinstance(v, str):
378377
return v
379378

src/runloop_api_client/lib/polling_async.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import time
22
import asyncio
33
from typing import Union, TypeVar, Callable, Optional, Awaitable
4+
from contextlib import suppress
45

56
from .polling import PollingConfig, PollingTimeout
67
from .cancellation import CancellationToken
@@ -67,13 +68,13 @@ async def async_poll_until(
6768

6869
# Cancellable async sleep
6970
if cancellation_token is not None:
71+
wait_task = asyncio.create_task(cancellation_token.async_event.wait())
7072
try:
71-
await asyncio.wait_for(
72-
cancellation_token.async_event.wait(),
73-
timeout=config.interval_seconds,
74-
)
73+
await asyncio.wait_for(wait_task, timeout=config.interval_seconds)
7574
cancellation_token.raise_if_cancelled()
7675
except asyncio.TimeoutError:
77-
pass # Normal sleep completion
76+
wait_task.cancel()
77+
with suppress(asyncio.CancelledError):
78+
await wait_task
7879
else:
7980
await asyncio.sleep(config.interval_seconds)

src/runloop_api_client/resources/axons/axons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
AsyncSqlResourceWithStreamingResponse,
1717
)
1818
from ...types import axon_list_params, axon_create_params, axon_publish_params
19-
from ...types.axons import axon_subscribe_sse_params
2019
from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
2120
from ..._utils import path_template, maybe_transform, async_maybe_transform
2221
from ..._compat import cached_property
@@ -30,6 +29,7 @@
3029
from ..._constants import RAW_RESPONSE_HEADER
3130
from ..._streaming import Stream, AsyncStream, ReconnectingStream, AsyncReconnectingStream
3231
from ...pagination import SyncAxonsCursorIDPage, AsyncAxonsCursorIDPage
32+
from ...types.axons import axon_subscribe_sse_params
3333
from ..._base_client import AsyncPaginator, make_request_options
3434
from ...types.axon_view import AxonView
3535
from ...types.axon_event_view import AxonEventView

src/runloop_api_client/resources/blueprints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
from .._exceptions import RunloopError
2929
from ..lib.polling import PollingConfig, poll_until
3030
from .._base_client import AsyncPaginator, make_request_options
31-
from ..lib.polling_async import async_poll_until
3231
from ..lib.cancellation import CancellationToken
32+
from ..lib.polling_async import async_poll_until
3333
from .._utils._validation import ValidationNotification
3434
from ..types.blueprint_view import BlueprintView
3535
from ..types.blueprint_preview_view import BlueprintPreviewView

src/runloop_api_client/resources/devboxes/devboxes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@
9797
DiskSnapshotsResourceWithStreamingResponse,
9898
AsyncDiskSnapshotsResourceWithStreamingResponse,
9999
)
100-
from ...lib.polling_async import async_poll_until
101100
from ...lib.cancellation import CancellationToken
101+
from ...lib.polling_async import async_poll_until
102102
from ...types.devbox_view import DevboxView
103103
from ...types.tunnel_view import TunnelView
104104
from ...types.shared_params.mount import Mount

src/runloop_api_client/resources/devboxes/disk_snapshots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
from ...lib.polling import PollingConfig, poll_until
2222
from ..._base_client import AsyncPaginator, make_request_options
2323
from ...types.devboxes import disk_snapshot_list_params, disk_snapshot_update_params
24-
from ...lib.polling_async import async_poll_until
2524
from ...lib.cancellation import CancellationToken
25+
from ...lib.polling_async import async_poll_until
2626
from ...types.devbox_snapshot_view import DevboxSnapshotView
2727
from ...types.devboxes.devbox_snapshot_async_status_view import DevboxSnapshotAsyncStatusView
2828

src/runloop_api_client/resources/devboxes/executions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
execution_stream_stderr_updates_params,
3333
execution_stream_stdout_updates_params,
3434
)
35-
from ...lib.polling_async import async_poll_until
3635
from ...lib.cancellation import CancellationToken
36+
from ...lib.polling_async import async_poll_until
3737
from ...types.devbox_send_std_in_result import DevboxSendStdInResult
3838
from ...types.devbox_execution_detail_view import DevboxExecutionDetailView
3939
from ...types.devboxes.execution_update_chunk import ExecutionUpdateChunk

src/runloop_api_client/resources/scenarios/runs.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
from ...lib.polling import PollingConfig, poll_until
2828
from ..._base_client import AsyncPaginator, make_request_options
2929
from ...types.scenarios import run_list_params
30-
from ...lib.polling_async import async_poll_until
3130
from ...lib.cancellation import CancellationToken
31+
from ...lib.polling_async import async_poll_until
3232
from ...types.scenario_run_view import ScenarioRunView
3333

3434
__all__ = ["RunsResource", "AsyncRunsResource"]
@@ -429,6 +429,7 @@ def score_and_complete(
429429
id: str,
430430
*,
431431
polling_config: PollingConfig | None = None,
432+
cancellation_token: CancellationToken | None = None,
432433
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
433434
# The extra values given here take precedence over values defined on the client or passed to this method.
434435
extra_headers: Headers | None = None,
@@ -441,6 +442,7 @@ def score_and_complete(
441442
Args:
442443
id: The ID of the scenario run to score, wait for, and complete
443444
polling_config: Optional polling configuration
445+
cancellation_token: Token to cancel the wait operation
444446
extra_headers: Send extra headers
445447
extra_query: Add additional query parameters to the request
446448
extra_body: Add additional JSON properties to the request
@@ -456,6 +458,7 @@ def score_and_complete(
456458
self.score_and_await(
457459
id,
458460
polling_config=polling_config,
461+
cancellation_token=cancellation_token,
459462
extra_headers=extra_headers,
460463
extra_query=extra_query,
461464
extra_body=extra_body,
@@ -866,6 +869,7 @@ async def score_and_complete(
866869
id: str,
867870
*,
868871
polling_config: PollingConfig | None = None,
872+
cancellation_token: CancellationToken | None = None,
869873
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
870874
# The extra values given here take precedence over values defined on the client or passed to this method.
871875
extra_headers: Headers | None = None,
@@ -878,6 +882,7 @@ async def score_and_complete(
878882
Args:
879883
id: The ID of the scenario run to score, wait for, and complete
880884
polling_config: Optional polling configuration
885+
cancellation_token: Token to cancel the wait operation
881886
extra_headers: Send extra headers
882887
extra_query: Add additional query parameters to the request
883888
extra_body: Add additional JSON properties to the request
@@ -893,6 +898,7 @@ async def score_and_complete(
893898
await self.score_and_await(
894899
id,
895900
polling_config=polling_config,
901+
cancellation_token=cancellation_token,
896902
extra_headers=extra_headers,
897903
extra_query=extra_query,
898904
extra_body=extra_body,

0 commit comments

Comments
 (0)