From c6e0a31a08f20d117ce634d6833869ac56cf5249 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 30 Apr 2026 05:21:48 +0000 Subject: [PATCH 1/6] codegen metadata --- .stats.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.stats.yml b/.stats.yml index fd3b5f7..b03ce9d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 1 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthale%2Fanthale-fc994b8d287ffe80cbc443e33b5f9b0e10e925151118140be8a2e7ed2517c338.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthale/anthale-fc994b8d287ffe80cbc443e33b5f9b0e10e925151118140be8a2e7ed2517c338.yml openapi_spec_hash: 8a77e29c614c175ce40883c430558c1f config_hash: 25d19bd2369a4230a4c4098e6824b504 From 0b2bfbe83e67dea2b4467e958cd6e986fe10a0e7 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 1 May 2026 04:08:39 +0000 Subject: [PATCH 2/6] codegen metadata --- .stats.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.stats.yml b/.stats.yml index b03ce9d..18cdc72 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 1 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthale/anthale-fc994b8d287ffe80cbc443e33b5f9b0e10e925151118140be8a2e7ed2517c338.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthale/anthale-8f8e4296712dc5cf29d3f877efe63e1a76cbb60032adb6ef5e549abc85b13484.yml openapi_spec_hash: 8a77e29c614c175ce40883c430558c1f config_hash: 25d19bd2369a4230a4c4098e6824b504 From 1f3e9cda83821497aacefff3dafc25926b336068 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 1 May 2026 04:12:15 +0000 Subject: [PATCH 3/6] chore(internal): reformat pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ef917cb..9d20425 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -159,7 +159,7 @@ show_error_codes = true # # We also exclude our `tests` as mypy doesn't always infer # types correctly and Pyright will still catch any type errors. -exclude = ['src/anthale/_files.py', '_dev/.*.py', 'tests/.*'] +exclude = ["src/anthale/_files.py", "_dev/.*.py", "tests/.*"] strict_equality = true implicit_reexport = true From 11d5d8c4fc38cc60610a1e85571f7b122d3ef118 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 9 May 2026 03:36:14 +0000 Subject: [PATCH 4/6] fix(client): add missing f-string prefix in file type error message --- src/anthale/_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/anthale/_files.py b/src/anthale/_files.py index 0fdce17..76da9e0 100644 --- a/src/anthale/_files.py +++ b/src/anthale/_files.py @@ -99,7 +99,7 @@ async def async_to_httpx_files(files: RequestFiles | None) -> HttpxRequestFiles elif is_sequence_t(files): files = [(key, await _async_transform_file(file)) for key, file in files] else: - raise TypeError("Unexpected file type input {type(files)}, expected mapping or sequence") + raise TypeError(f"Unexpected file type input {type(files)}, expected mapping or sequence") return files From 2e3ff8d3f77e53d5404ce6763c901b9dcfbdda6b Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 12 May 2026 03:29:18 +0000 Subject: [PATCH 5/6] feat(internal/types): support eagerly validating pydantic iterators --- src/anthale/_models.py | 80 ++++++++++++++++++++++++++++++++++++++++++ tests/test_models.py | 60 +++++++++++++++++++++++++++++-- 2 files changed, 137 insertions(+), 3 deletions(-) diff --git a/src/anthale/_models.py b/src/anthale/_models.py index 29070e0..8c5ab26 100644 --- a/src/anthale/_models.py +++ b/src/anthale/_models.py @@ -25,7 +25,9 @@ ClassVar, Protocol, Required, + Annotated, ParamSpec, + TypeAlias, TypedDict, TypeGuard, final, @@ -79,7 +81,15 @@ from ._constants import RAW_RESPONSE_HEADER if TYPE_CHECKING: + from pydantic import GetCoreSchemaHandler, ValidatorFunctionWrapHandler + from pydantic_core import CoreSchema, core_schema from pydantic_core.core_schema import ModelField, ModelSchema, LiteralSchema, ModelFieldsSchema +else: + try: + from pydantic_core import CoreSchema, core_schema + except ImportError: + CoreSchema = None + core_schema = None __all__ = ["BaseModel", "GenericModel"] @@ -396,6 +406,76 @@ def model_dump_json( ) +class _EagerIterable(list[_T], Generic[_T]): + """ + Accepts any Iterable[T] input (including generators), consumes it + eagerly, and validates all items upfront. + + Validation preserves the original container type where possible + (e.g. a set[T] stays a set[T]). Serialization (model_dump / JSON) + always emits a list — round-tripping through model_dump() will not + restore the original container type. + """ + + @classmethod + def __get_pydantic_core_schema__( + cls, + source_type: Any, + handler: GetCoreSchemaHandler, + ) -> CoreSchema: + (item_type,) = get_args(source_type) or (Any,) + item_schema: CoreSchema = handler.generate_schema(item_type) + list_of_items_schema: CoreSchema = core_schema.list_schema(item_schema) + + return core_schema.no_info_wrap_validator_function( + cls._validate, + list_of_items_schema, + serialization=core_schema.plain_serializer_function_ser_schema( + cls._serialize, + info_arg=False, + ), + ) + + @staticmethod + def _validate(v: Iterable[_T], handler: "ValidatorFunctionWrapHandler") -> Any: + original_type: type[Any] = type(v) + + # Normalize to list so list_schema can validate each item + if isinstance(v, list): + items: list[_T] = v + else: + try: + items = list(v) + except TypeError as e: + raise TypeError("Value is not iterable") from e + + # Validate items against the inner schema + validated: list[_T] = handler(items) + + # Reconstruct original container type + if original_type is list: + return validated + # str(list) produces the list's repr, not a string built from items, + # so skip reconstruction for str and its subclasses. + if issubclass(original_type, str): + return validated + try: + return original_type(validated) + except (TypeError, ValueError): + # If the type cannot be reconstructed, just return the validated list + return validated + + @staticmethod + def _serialize(v: Iterable[_T]) -> list[_T]: + """Always serialize as a list so Pydantic's JSON encoder is happy.""" + if isinstance(v, list): + return v + return list(v) + + +EagerIterable: TypeAlias = Annotated[Iterable[_T], _EagerIterable] + + def _construct_field(value: object, field: FieldInfo, key: str) -> object: if value is None: return field_get_default(field) diff --git a/tests/test_models.py b/tests/test_models.py index c705b2e..54662dd 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,7 +1,8 @@ import json -from typing import TYPE_CHECKING, Any, Dict, List, Union, Optional, cast +from typing import TYPE_CHECKING, Any, Dict, List, Union, Iterable, Optional, cast from datetime import datetime, timezone -from typing_extensions import Literal, Annotated, TypeAliasType +from collections import deque +from typing_extensions import Literal, Annotated, TypedDict, TypeAliasType import pytest import pydantic @@ -9,7 +10,7 @@ from anthale._utils import PropertyInfo from anthale._compat import PYDANTIC_V1, parse_obj, model_dump, model_json -from anthale._models import DISCRIMINATOR_CACHE, BaseModel, construct_type +from anthale._models import DISCRIMINATOR_CACHE, BaseModel, EagerIterable, construct_type class BasicModel(BaseModel): @@ -961,3 +962,56 @@ def __getattr__(self, attr: str) -> Item: ... assert model.a.prop == 1 assert isinstance(model.a, Item) assert model.other == "foo" + + +# NOTE: Workaround for Pydantic Iterable behavior. +# Iterable fields are replaced with a ValidatorIterator and may be consumed +# during serialization, which can cause subsequent dumps to return empty data. +# See: https://github.com/pydantic/pydantic/issues/9541 +@pytest.mark.parametrize( + "data, expected_validated", + [ + ([1, 2, 3], [1, 2, 3]), + ((1, 2, 3), (1, 2, 3)), + (set([1, 2, 3]), set([1, 2, 3])), + (iter([1, 2, 3]), [1, 2, 3]), + ([], []), + ((x for x in [1, 2, 3]), [1, 2, 3]), + (map(lambda x: x, [1, 2, 3]), [1, 2, 3]), + (frozenset([1, 2, 3]), frozenset([1, 2, 3])), + (deque([1, 2, 3]), deque([1, 2, 3])), + ], + ids=["list", "tuple", "set", "iterator", "empty", "generator", "map", "frozenset", "deque"], +) +@pytest.mark.skipif(PYDANTIC_V1, reason="this is only supported in pydantic v2") +def test_iterable_construction(data: Iterable[int], expected_validated: Iterable[int]) -> None: + class TypeWithIterable(TypedDict): + items: EagerIterable[int] + + class Model(BaseModel): + data: TypeWithIterable + + m = Model.model_validate({"data": {"items": data}}) + assert m.data["items"] == expected_validated + + # Verify repeated dumps don't lose data (the original bug) + assert m.model_dump()["data"]["items"] == list(expected_validated) + assert m.model_dump()["data"]["items"] == list(expected_validated) + + +@pytest.mark.skipif(PYDANTIC_V1, reason="this is only supported in pydantic v2") +def test_iterable_construction_str_falls_back_to_list() -> None: + # str is iterable (over chars), but str(list_of_chars) produces the list's repr + # rather than reconstructing a string from items. We special-case str to fall + # back to list instead of attempting reconstruction. + class TypeWithIterable(TypedDict): + items: EagerIterable[str] + + class Model(BaseModel): + data: TypeWithIterable + + m = Model.model_validate({"data": {"items": "hello"}}) + + # falls back to list of chars rather than calling str(["h", "e", "l", "l", "o"]) + assert m.data["items"] == ["h", "e", "l", "l", "o"] + assert m.model_dump()["data"]["items"] == ["h", "e", "l", "l", "o"] From 30b3e3fecb9abe68f117561f949b363886348988 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 12 May 2026 03:30:00 +0000 Subject: [PATCH 6/6] release: 0.9.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 18 ++++++++++++++++++ pyproject.toml | 2 +- src/anthale/_version.py | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 6538ca9..6d78745 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.8.0" + ".": "0.9.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ace96af..b23f733 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog +## 0.9.0 (2026-05-12) + +Full Changelog: [v0.8.0...v0.9.0](https://github.com/anthalehq/anthale-python/compare/v0.8.0...v0.9.0) + +### Features + +* **internal/types:** support eagerly validating pydantic iterators ([2e3ff8d](https://github.com/anthalehq/anthale-python/commit/2e3ff8d3f77e53d5404ce6763c901b9dcfbdda6b)) + + +### Bug Fixes + +* **client:** add missing f-string prefix in file type error message ([11d5d8c](https://github.com/anthalehq/anthale-python/commit/11d5d8c4fc38cc60610a1e85571f7b122d3ef118)) + + +### Chores + +* **internal:** reformat pyproject.toml ([1f3e9cd](https://github.com/anthalehq/anthale-python/commit/1f3e9cda83821497aacefff3dafc25926b336068)) + ## 0.8.0 (2026-04-28) Full Changelog: [v0.7.2...v0.8.0](https://github.com/anthalehq/anthale-python/compare/v0.7.2...v0.8.0) diff --git a/pyproject.toml b/pyproject.toml index 9d20425..0f6276b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "anthale" -version = "0.8.0" +version = "0.9.0" description = "The official Python library for the anthale API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/src/anthale/_version.py b/src/anthale/_version.py index 1d7456b..0693c8d 100644 --- a/src/anthale/_version.py +++ b/src/anthale/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "anthale" -__version__ = "0.8.0" # x-release-please-version +__version__ = "0.9.0" # x-release-please-version