From 48a9039f0f206e11ad85df3bbe6487c1a95186aa 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:34:55 +0000 Subject: [PATCH 1/4] feat(internal/types): support eagerly validating pydantic iterators --- src/onebusaway/_models.py | 80 +++++++++++++++++++++++++++++++++++++++ tests/test_models.py | 60 +++++++++++++++++++++++++++-- 2 files changed, 137 insertions(+), 3 deletions(-) diff --git a/src/onebusaway/_models.py b/src/onebusaway/_models.py index 29070e0..8c5ab26 100644 --- a/src/onebusaway/_models.py +++ b/src/onebusaway/_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 f73d5e1..89de508 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 onebusaway._utils import PropertyInfo from onebusaway._compat import PYDANTIC_V1, parse_obj, model_dump, model_json -from onebusaway._models import DISCRIMINATOR_CACHE, BaseModel, construct_type +from onebusaway._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 ed64c67e15a7ab241dc34697a424a52196408434 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 13 May 2026 02:54:14 +0000 Subject: [PATCH 2/4] ci: pin GitHub Actions to commit SHAs Pin all GitHub Actions referenced in generated workflows (both first-party `actions/*` and third-party) to immutable commit SHAs. Updating pinned actions is now a deliberate codegen-side bump rather than implicit on every workflow run. --- .github/workflows/ci.yml | 8 ++++---- .github/workflows/publish-pypi.yml | 2 +- .github/workflows/release-doctor.yml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35bbf55..22aaba7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: runs-on: ${{ github.repository == 'stainless-sdks/open-transit-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Install Rye run: | @@ -46,7 +46,7 @@ jobs: id-token: write runs-on: ${{ github.repository == 'stainless-sdks/open-transit-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Install Rye run: | @@ -67,7 +67,7 @@ jobs: github.repository == 'stainless-sdks/open-transit-python' && !startsWith(github.ref, 'refs/heads/stl/') id: github-oidc - uses: actions/github-script@v8 + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 with: script: core.setOutput('github_token', await core.getIDToken()); @@ -87,7 +87,7 @@ jobs: runs-on: ${{ github.repository == 'stainless-sdks/open-transit-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} if: github.event_name == 'push' || github.event.pull_request.head.repo.fork steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Install Rye run: | diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index 5da47ec..8a7742d 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Install Rye run: | diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml index 421021c..62dcbfa 100644 --- a/.github/workflows/release-doctor.yml +++ b/.github/workflows/release-doctor.yml @@ -12,7 +12,7 @@ jobs: if: github.repository == 'OneBusAway/python-sdk' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next') steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Check release environment run: | From 7f9712d23e5ddecb310ae8138b5a8357e69eafd4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 20 May 2026 03:29:17 +0000 Subject: [PATCH 3/4] feat(api): api update --- .stats.yml | 4 ++-- src/onebusaway/types/trip_detail_retrieve_response.py | 3 +++ src/onebusaway/types/trip_for_vehicle_retrieve_response.py | 3 +++ src/onebusaway/types/trips_for_location_list_response.py | 3 +++ src/onebusaway/types/trips_for_route_list_response.py | 3 +++ src/onebusaway/types/vehicles_for_agency_list_response.py | 3 +++ 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 6608e4d..62a092e 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 30 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/open-transit/open-transit-b625345de7b9c51744ddc6c75b8c37a159a536204481404cca91d7d6a859149d.yml -openapi_spec_hash: 9bf1e5bf00ef9936a9181ebd0956d5b8 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/open-transit/open-transit-4a35fd1e705bc2b75f44e2fd82144b95eeb56f329e4e05bbede7e6bc8adc479e.yml +openapi_spec_hash: bc73be5518578c9ad8e878b82c540691 config_hash: c28ddf5b7754155603d9fd1c5fcaeeff diff --git a/src/onebusaway/types/trip_detail_retrieve_response.py b/src/onebusaway/types/trip_detail_retrieve_response.py index ccb12cc..861f4b2 100644 --- a/src/onebusaway/types/trip_detail_retrieve_response.py +++ b/src/onebusaway/types/trip_detail_retrieve_response.py @@ -67,6 +67,8 @@ class TripDetailRetrieveResponseDataEntryStatusPosition(BaseModel): class TripDetailRetrieveResponseDataEntryStatus(BaseModel): + """Trip-specific status for the arriving transit vehicle.""" + active_trip_id: str = FieldInfo(alias="activeTripId") """Trip ID of the trip the vehicle is actively serving.""" @@ -178,6 +180,7 @@ class TripDetailRetrieveResponseDataEntry(BaseModel): situation_ids: Optional[List[str]] = FieldInfo(alias="situationIds", default=None) status: Optional[TripDetailRetrieveResponseDataEntryStatus] = None + """Trip-specific status for the arriving transit vehicle.""" class TripDetailRetrieveResponseData(BaseModel): diff --git a/src/onebusaway/types/trip_for_vehicle_retrieve_response.py b/src/onebusaway/types/trip_for_vehicle_retrieve_response.py index d7f7ee9..86aee0c 100644 --- a/src/onebusaway/types/trip_for_vehicle_retrieve_response.py +++ b/src/onebusaway/types/trip_for_vehicle_retrieve_response.py @@ -67,6 +67,8 @@ class TripForVehicleRetrieveResponseDataEntryStatusPosition(BaseModel): class TripForVehicleRetrieveResponseDataEntryStatus(BaseModel): + """Trip-specific status for the arriving transit vehicle.""" + active_trip_id: str = FieldInfo(alias="activeTripId") """Trip ID of the trip the vehicle is actively serving.""" @@ -178,6 +180,7 @@ class TripForVehicleRetrieveResponseDataEntry(BaseModel): situation_ids: Optional[List[str]] = FieldInfo(alias="situationIds", default=None) status: Optional[TripForVehicleRetrieveResponseDataEntryStatus] = None + """Trip-specific status for the arriving transit vehicle.""" class TripForVehicleRetrieveResponseData(BaseModel): diff --git a/src/onebusaway/types/trips_for_location_list_response.py b/src/onebusaway/types/trips_for_location_list_response.py index 9530952..0c208d5 100644 --- a/src/onebusaway/types/trips_for_location_list_response.py +++ b/src/onebusaway/types/trips_for_location_list_response.py @@ -67,6 +67,8 @@ class TripsForLocationListResponseDataListStatusPosition(BaseModel): class TripsForLocationListResponseDataListStatus(BaseModel): + """Trip-specific status for the arriving transit vehicle.""" + active_trip_id: str = FieldInfo(alias="activeTripId") """Trip ID of the trip the vehicle is actively serving.""" @@ -170,6 +172,7 @@ class TripsForLocationListResponseDataList(BaseModel): schedule: TripsForLocationListResponseDataListSchedule status: TripsForLocationListResponseDataListStatus + """Trip-specific status for the arriving transit vehicle.""" trip_id: str = FieldInfo(alias="tripId") diff --git a/src/onebusaway/types/trips_for_route_list_response.py b/src/onebusaway/types/trips_for_route_list_response.py index e7ecb00..b35f71a 100644 --- a/src/onebusaway/types/trips_for_route_list_response.py +++ b/src/onebusaway/types/trips_for_route_list_response.py @@ -67,6 +67,8 @@ class TripsForRouteListResponseDataListStatusPosition(BaseModel): class TripsForRouteListResponseDataListStatus(BaseModel): + """Trip-specific status for the arriving transit vehicle.""" + active_trip_id: str = FieldInfo(alias="activeTripId") """Trip ID of the trip the vehicle is actively serving.""" @@ -170,6 +172,7 @@ class TripsForRouteListResponseDataList(BaseModel): schedule: TripsForRouteListResponseDataListSchedule status: TripsForRouteListResponseDataListStatus + """Trip-specific status for the arriving transit vehicle.""" trip_id: str = FieldInfo(alias="tripId") diff --git a/src/onebusaway/types/vehicles_for_agency_list_response.py b/src/onebusaway/types/vehicles_for_agency_list_response.py index 0cb3e14..40c40e0 100644 --- a/src/onebusaway/types/vehicles_for_agency_list_response.py +++ b/src/onebusaway/types/vehicles_for_agency_list_response.py @@ -46,6 +46,8 @@ class VehiclesForAgencyListResponseDataListTripStatusPosition(BaseModel): class VehiclesForAgencyListResponseDataListTripStatus(BaseModel): + """Trip-specific status for the arriving transit vehicle.""" + active_trip_id: str = FieldInfo(alias="activeTripId") """Trip ID of the trip the vehicle is actively serving.""" @@ -167,6 +169,7 @@ class VehiclesForAgencyListResponseDataList(BaseModel): trip_id: Optional[str] = FieldInfo(alias="tripId", default=None) trip_status: Optional[VehiclesForAgencyListResponseDataListTripStatus] = FieldInfo(alias="tripStatus", default=None) + """Trip-specific status for the arriving transit vehicle.""" class VehiclesForAgencyListResponseData(BaseModel): From fa59ef68c2f2cd4708599372faf75587307f21ba Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 20 May 2026 03:29:46 +0000 Subject: [PATCH 4/4] release: 1.26.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 9 +++++++++ pyproject.toml | 2 +- src/onebusaway/_version.py | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 6994d4c..f3dbfd2 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.25.2" + ".": "1.26.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 58a341b..b67d469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 1.26.0 (2026-05-20) + +Full Changelog: [v1.25.2...v1.26.0](https://github.com/OneBusAway/python-sdk/compare/v1.25.2...v1.26.0) + +### Features + +* **api:** api update ([7f9712d](https://github.com/OneBusAway/python-sdk/commit/7f9712d23e5ddecb310ae8138b5a8357e69eafd4)) +* **internal/types:** support eagerly validating pydantic iterators ([48a9039](https://github.com/OneBusAway/python-sdk/commit/48a9039f0f206e11ad85df3bbe6487c1a95186aa)) + ## 1.25.2 (2026-05-09) Full Changelog: [v1.25.1...v1.25.2](https://github.com/OneBusAway/python-sdk/compare/v1.25.1...v1.25.2) diff --git a/pyproject.toml b/pyproject.toml index bb8625c..33a1a39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "onebusaway" -version = "1.25.2" +version = "1.26.0" description = "The official Python library for the onebusaway-sdk API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/src/onebusaway/_version.py b/src/onebusaway/_version.py index 4dc7a91..32a985f 100644 --- a/src/onebusaway/_version.py +++ b/src/onebusaway/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "onebusaway" -__version__ = "1.25.2" # x-release-please-version +__version__ = "1.26.0" # x-release-please-version