Skip to content

Commit b32a1fa

Browse files
authored
Merge pull request #203 from scaleapi/release-please--branches--main--changes--next
release: 0.6.6
2 parents ce55653 + 6ec37ae commit b32a1fa

File tree

8 files changed

+65
-56
lines changed

8 files changed

+65
-56
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.6.5"
2+
".": "0.6.6"
33
}

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 36
1+
configured_endpoints: 34
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/sgp%2Fagentex-sdk-17022011bf153e3ac9e20d23c5dca8a3072b0e735b47bb391b6e35b00348d5a5.yml
33
openapi_spec_hash: 0927cdce49a6e6915d6060c2ab43b0d0
4-
config_hash: 758ca2ffe20517da913adf250c924c8a
4+
config_hash: 0197f86ba1a4b1b5ce813d0e62138588

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## 0.6.6 (2025-11-12)
4+
5+
Full Changelog: [v0.6.5...v0.6.6](https://github.com/scaleapi/scale-agentex-python/compare/v0.6.5...v0.6.6)
6+
7+
### Bug Fixes
8+
9+
* compat with Python 3.14 ([9a62f23](https://github.com/scaleapi/scale-agentex-python/commit/9a62f23376ef797bafe67f61552eb7635286caa3))
10+
* **compat:** update signatures of `model_dump` and `model_dump_json` for Pydantic v1 ([cf857f9](https://github.com/scaleapi/scale-agentex-python/commit/cf857f9191f10a971e9cba2a8c764229ed4a7dfe))
11+
12+
13+
### Chores
14+
15+
* **internal:** restore stats ([5ec0383](https://github.com/scaleapi/scale-agentex-python/commit/5ec0383d9d6a85b342263ba49b8e3893924c59fc))
16+
* **package:** drop Python 3.8 support ([3d4dc37](https://github.com/scaleapi/scale-agentex-python/commit/3d4dc37f87b8d8f1debbe6505746342e461772ba))
17+
318
## 0.6.5 (2025-11-06)
419

520
Full Changelog: [v0.6.4...v0.6.5](https://github.com/scaleapi/scale-agentex-python/compare/v0.6.4...v0.6.5)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- prettier-ignore -->
55
[![PyPI version](https://img.shields.io/pypi/v/agentex-sdk.svg?label=pypi%20(stable))](https://pypi.org/project/agentex-sdk/)
66

7-
The Agentex Python library provides convenient access to the Agentex REST API from any Python 3.8+
7+
The Agentex Python library provides convenient access to the Agentex REST API from any Python 3.9+
88
application. The library includes type definitions for all request params and response fields,
99
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
1010

@@ -389,7 +389,7 @@ print(agentex.__version__)
389389

390390
## Requirements
391391

392-
Python 3.8 or higher.
392+
Python 3.9 or higher.
393393

394394
## Contributing
395395

src/agentex/_models.py

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

33
import os
44
import inspect
5+
import weakref
56
from typing import TYPE_CHECKING, Any, Type, Union, Generic, TypeVar, Callable, Optional, cast
67
from datetime import date, datetime
78
from typing_extensions import (
@@ -256,32 +257,41 @@ def model_dump(
256257
mode: Literal["json", "python"] | str = "python",
257258
include: IncEx | None = None,
258259
exclude: IncEx | None = None,
260+
context: Any | None = None,
259261
by_alias: bool | None = None,
260262
exclude_unset: bool = False,
261263
exclude_defaults: bool = False,
262264
exclude_none: bool = False,
265+
exclude_computed_fields: bool = False,
263266
round_trip: bool = False,
264267
warnings: bool | Literal["none", "warn", "error"] = True,
265-
context: dict[str, Any] | None = None,
266-
serialize_as_any: bool = False,
267268
fallback: Callable[[Any], Any] | None = None,
269+
serialize_as_any: bool = False,
268270
) -> dict[str, Any]:
269271
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
270272
271273
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
272274
273275
Args:
274276
mode: The mode in which `to_python` should run.
275-
If mode is 'json', the dictionary will only contain JSON serializable types.
276-
If mode is 'python', the dictionary may contain any Python objects.
277-
include: A list of fields to include in the output.
278-
exclude: A list of fields to exclude from the output.
277+
If mode is 'json', the output will only contain JSON serializable types.
278+
If mode is 'python', the output may contain non-JSON-serializable Python objects.
279+
include: A set of fields to include in the output.
280+
exclude: A set of fields to exclude from the output.
281+
context: Additional context to pass to the serializer.
279282
by_alias: Whether to use the field's alias in the dictionary key if defined.
280-
exclude_unset: Whether to exclude fields that are unset or None from the output.
281-
exclude_defaults: Whether to exclude fields that are set to their default value from the output.
282-
exclude_none: Whether to exclude fields that have a value of `None` from the output.
283-
round_trip: Whether to enable serialization and deserialization round-trip support.
284-
warnings: Whether to log warnings when invalid fields are encountered.
283+
exclude_unset: Whether to exclude fields that have not been explicitly set.
284+
exclude_defaults: Whether to exclude fields that are set to their default value.
285+
exclude_none: Whether to exclude fields that have a value of `None`.
286+
exclude_computed_fields: Whether to exclude computed fields.
287+
While this can be useful for round-tripping, it is usually recommended to use the dedicated
288+
`round_trip` parameter instead.
289+
round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T].
290+
warnings: How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
291+
"error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
292+
fallback: A function to call when an unknown value is encountered. If not provided,
293+
a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError] error is raised.
294+
serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.
285295
286296
Returns:
287297
A dictionary representation of the model.
@@ -298,6 +308,8 @@ def model_dump(
298308
raise ValueError("serialize_as_any is only supported in Pydantic v2")
299309
if fallback is not None:
300310
raise ValueError("fallback is only supported in Pydantic v2")
311+
if exclude_computed_fields != False:
312+
raise ValueError("exclude_computed_fields is only supported in Pydantic v2")
301313
dumped = super().dict( # pyright: ignore[reportDeprecated]
302314
include=include,
303315
exclude=exclude,
@@ -314,15 +326,17 @@ def model_dump_json(
314326
self,
315327
*,
316328
indent: int | None = None,
329+
ensure_ascii: bool = False,
317330
include: IncEx | None = None,
318331
exclude: IncEx | None = None,
332+
context: Any | None = None,
319333
by_alias: bool | None = None,
320334
exclude_unset: bool = False,
321335
exclude_defaults: bool = False,
322336
exclude_none: bool = False,
337+
exclude_computed_fields: bool = False,
323338
round_trip: bool = False,
324339
warnings: bool | Literal["none", "warn", "error"] = True,
325-
context: dict[str, Any] | None = None,
326340
fallback: Callable[[Any], Any] | None = None,
327341
serialize_as_any: bool = False,
328342
) -> str:
@@ -354,6 +368,10 @@ def model_dump_json(
354368
raise ValueError("serialize_as_any is only supported in Pydantic v2")
355369
if fallback is not None:
356370
raise ValueError("fallback is only supported in Pydantic v2")
371+
if ensure_ascii != False:
372+
raise ValueError("ensure_ascii is only supported in Pydantic v2")
373+
if exclude_computed_fields != False:
374+
raise ValueError("exclude_computed_fields is only supported in Pydantic v2")
357375
return super().json( # type: ignore[reportDeprecated]
358376
indent=indent,
359377
include=include,
@@ -573,6 +591,9 @@ class CachedDiscriminatorType(Protocol):
573591
__discriminator__: DiscriminatorDetails
574592

575593

594+
DISCRIMINATOR_CACHE: weakref.WeakKeyDictionary[type, DiscriminatorDetails] = weakref.WeakKeyDictionary()
595+
596+
576597
class DiscriminatorDetails:
577598
field_name: str
578599
"""The name of the discriminator field in the variant class, e.g.
@@ -615,8 +636,9 @@ def __init__(
615636

616637

617638
def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any, ...]) -> DiscriminatorDetails | None:
618-
if isinstance(union, CachedDiscriminatorType):
619-
return union.__discriminator__
639+
cached = DISCRIMINATOR_CACHE.get(union)
640+
if cached is not None:
641+
return cached
620642

621643
discriminator_field_name: str | None = None
622644

@@ -669,7 +691,7 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
669691
discriminator_field=discriminator_field_name,
670692
discriminator_alias=discriminator_alias,
671693
)
672-
cast(CachedDiscriminatorType, union).__discriminator__ = details
694+
DISCRIMINATOR_CACHE.setdefault(union, details)
673695
return details
674696

675697

src/agentex/_utils/_sync.py

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from __future__ import annotations
22

3-
import sys
43
import asyncio
54
import functools
6-
import contextvars
7-
from typing import Any, TypeVar, Callable, Awaitable
5+
from typing import TypeVar, Callable, Awaitable
86
from typing_extensions import ParamSpec
97

108
import anyio
@@ -15,34 +13,11 @@
1513
T_ParamSpec = ParamSpec("T_ParamSpec")
1614

1715

18-
if sys.version_info >= (3, 9):
19-
_asyncio_to_thread = asyncio.to_thread
20-
else:
21-
# backport of https://docs.python.org/3/library/asyncio-task.html#asyncio.to_thread
22-
# for Python 3.8 support
23-
async def _asyncio_to_thread(
24-
func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
25-
) -> Any:
26-
"""Asynchronously run function *func* in a separate thread.
27-
28-
Any *args and **kwargs supplied for this function are directly passed
29-
to *func*. Also, the current :class:`contextvars.Context` is propagated,
30-
allowing context variables from the main thread to be accessed in the
31-
separate thread.
32-
33-
Returns a coroutine that can be awaited to get the eventual result of *func*.
34-
"""
35-
loop = asyncio.events.get_running_loop()
36-
ctx = contextvars.copy_context()
37-
func_call = functools.partial(ctx.run, func, *args, **kwargs)
38-
return await loop.run_in_executor(None, func_call)
39-
40-
4116
async def to_thread(
4217
func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
4318
) -> T_Retval:
4419
if sniffio.current_async_library() == "asyncio":
45-
return await _asyncio_to_thread(func, *args, **kwargs)
20+
return await asyncio.to_thread(func, *args, **kwargs)
4621

4722
return await anyio.to_thread.run_sync(
4823
functools.partial(func, *args, **kwargs),
@@ -53,10 +28,7 @@ async def to_thread(
5328
def asyncify(function: Callable[T_ParamSpec, T_Retval]) -> Callable[T_ParamSpec, Awaitable[T_Retval]]:
5429
"""
5530
Take a blocking function and create an async one that receives the same
56-
positional and keyword arguments. For python version 3.9 and above, it uses
57-
asyncio.to_thread to run the function in a separate thread. For python version
58-
3.8, it uses locally defined copy of the asyncio.to_thread function which was
59-
introduced in python 3.9.
31+
positional and keyword arguments.
6032
6133
Usage:
6234

src/agentex/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
__title__ = "agentex"
4-
__version__ = "0.6.5" # x-release-please-version
4+
__version__ = "0.6.6" # x-release-please-version

tests/test_models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from agentex._utils import PropertyInfo
1111
from agentex._compat import PYDANTIC_V1, parse_obj, model_dump, model_json
12-
from agentex._models import BaseModel, construct_type
12+
from agentex._models import DISCRIMINATOR_CACHE, BaseModel, construct_type
1313

1414

1515
class BasicModel(BaseModel):
@@ -809,7 +809,7 @@ class B(BaseModel):
809809

810810
UnionType = cast(Any, Union[A, B])
811811

812-
assert not hasattr(UnionType, "__discriminator__")
812+
assert not DISCRIMINATOR_CACHE.get(UnionType)
813813

814814
m = construct_type(
815815
value={"type": "b", "data": "foo"}, type_=cast(Any, Annotated[UnionType, PropertyInfo(discriminator="type")])
@@ -818,7 +818,7 @@ class B(BaseModel):
818818
assert m.type == "b"
819819
assert m.data == "foo" # type: ignore[comparison-overlap]
820820

821-
discriminator = UnionType.__discriminator__
821+
discriminator = DISCRIMINATOR_CACHE.get(UnionType)
822822
assert discriminator is not None
823823

824824
m = construct_type(
@@ -830,7 +830,7 @@ class B(BaseModel):
830830

831831
# if the discriminator details object stays the same between invocations then
832832
# we hit the cache
833-
assert UnionType.__discriminator__ is discriminator
833+
assert DISCRIMINATOR_CACHE.get(UnionType) is discriminator
834834

835835

836836
@pytest.mark.skipif(PYDANTIC_V1, reason="TypeAliasType is not supported in Pydantic v1")

0 commit comments

Comments
 (0)