mirror of
https://github.com/anomalyco/opencode-sdk-python.git
synced 2026-05-17 12:42:25 +00:00
feat: improve future compat with pydantic v3
This commit is contained in:
parent
86dbdbc8ee
commit
9350797779
13 changed files with 437 additions and 137 deletions
|
|
@ -15,7 +15,7 @@ from opencode_ai._utils import (
|
|||
parse_datetime,
|
||||
async_transform as _async_transform,
|
||||
)
|
||||
from opencode_ai._compat import PYDANTIC_V2
|
||||
from opencode_ai._compat import PYDANTIC_V1
|
||||
from opencode_ai._models import BaseModel
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
|
@ -189,7 +189,7 @@ class DateModel(BaseModel):
|
|||
@pytest.mark.asyncio
|
||||
async def test_iso8601_format(use_async: bool) -> None:
|
||||
dt = datetime.fromisoformat("2023-02-23T14:16:36.337692+00:00")
|
||||
tz = "Z" if PYDANTIC_V2 else "+00:00"
|
||||
tz = "+00:00" if PYDANTIC_V1 else "Z"
|
||||
assert await transform({"foo": dt}, DatetimeDict, use_async) == {"foo": "2023-02-23T14:16:36.337692+00:00"} # type: ignore[comparison-overlap]
|
||||
assert await transform(DatetimeModel(foo=dt), Any, use_async) == {"foo": "2023-02-23T14:16:36.337692" + tz} # type: ignore[comparison-overlap]
|
||||
|
||||
|
|
@ -297,11 +297,11 @@ async def test_pydantic_unknown_field(use_async: bool) -> None:
|
|||
@pytest.mark.asyncio
|
||||
async def test_pydantic_mismatched_types(use_async: bool) -> None:
|
||||
model = MyModel.construct(foo=True)
|
||||
if PYDANTIC_V2:
|
||||
if PYDANTIC_V1:
|
||||
params = await transform(model, Any, use_async)
|
||||
else:
|
||||
with pytest.warns(UserWarning):
|
||||
params = await transform(model, Any, use_async)
|
||||
else:
|
||||
params = await transform(model, Any, use_async)
|
||||
assert cast(Any, params) == {"foo": True}
|
||||
|
||||
|
||||
|
|
@ -309,11 +309,11 @@ async def test_pydantic_mismatched_types(use_async: bool) -> None:
|
|||
@pytest.mark.asyncio
|
||||
async def test_pydantic_mismatched_object_type(use_async: bool) -> None:
|
||||
model = MyModel.construct(foo=MyModel.construct(hello="world"))
|
||||
if PYDANTIC_V2:
|
||||
if PYDANTIC_V1:
|
||||
params = await transform(model, Any, use_async)
|
||||
else:
|
||||
with pytest.warns(UserWarning):
|
||||
params = await transform(model, Any, use_async)
|
||||
else:
|
||||
params = await transform(model, Any, use_async)
|
||||
assert cast(Any, params) == {"foo": {"hello": "world"}}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue