mirror of
https://github.com/anomalyco/opencode-sdk-python.git
synced 2026-08-14 11:05:12 +00:00
chore(internal): add Sequence related utils
This commit is contained in:
parent
82c499048e
commit
002bf6d3d6
4 changed files with 50 additions and 2 deletions
|
|
@ -4,7 +4,7 @@ import os
|
|||
import inspect
|
||||
import traceback
|
||||
import contextlib
|
||||
from typing import Any, TypeVar, Iterator, cast
|
||||
from typing import Any, TypeVar, Iterator, Sequence, cast
|
||||
from datetime import date, datetime
|
||||
from typing_extensions import Literal, get_args, get_origin, assert_type
|
||||
|
||||
|
|
@ -15,6 +15,7 @@ from opencode_ai._utils import (
|
|||
is_list_type,
|
||||
is_union_type,
|
||||
extract_type_arg,
|
||||
is_sequence_type,
|
||||
is_annotated_type,
|
||||
is_type_alias_type,
|
||||
)
|
||||
|
|
@ -71,6 +72,13 @@ def assert_matches_type(
|
|||
if is_list_type(type_):
|
||||
return _assert_list_type(type_, value)
|
||||
|
||||
if is_sequence_type(type_):
|
||||
assert isinstance(value, Sequence)
|
||||
inner_type = get_args(type_)[0]
|
||||
for entry in value: # type: ignore
|
||||
assert_type(inner_type, entry) # type: ignore
|
||||
return
|
||||
|
||||
if origin == str:
|
||||
assert isinstance(value, str)
|
||||
elif origin == int:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue