Skip to content

Commit 74d2649

Browse files
authored
Merge pull request #150 from lumalabs/release-please--branches--main--changes--next
release: 1.7.3
2 parents 94b0c2d + 929eabe commit 74d2649

File tree

11 files changed

+94
-13
lines changed

11 files changed

+94
-13
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
lint:
1313
name: lint
1414
runs-on: ubuntu-latest
15-
1615
steps:
1716
- uses: actions/checkout@v4
1817

@@ -33,7 +32,6 @@ jobs:
3332
test:
3433
name: test
3534
runs-on: ubuntu-latest
36-
3735
steps:
3836
- uses: actions/checkout@v4
3937

.release-please-manifest.json

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

CHANGELOG.md

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

3+
## 1.7.3 (2025-04-12)
4+
5+
Full Changelog: [v1.7.2...v1.7.3](https://github.com/lumalabs/lumaai-python/compare/v1.7.2...v1.7.3)
6+
7+
### Bug Fixes
8+
9+
* **perf:** optimize some hot paths ([ae01192](https://github.com/lumalabs/lumaai-python/commit/ae01192924c54d4a2a7d9a70d0df88e209163989))
10+
* **perf:** skip traversing types for NotGiven values ([43ac98d](https://github.com/lumalabs/lumaai-python/commit/43ac98d293f3e373ac986a4cabd036a54b1e8213))
11+
12+
13+
### Chores
14+
15+
* **internal:** expand CI branch coverage ([a006432](https://github.com/lumalabs/lumaai-python/commit/a00643219c4eebcfe34eca5046e5380a96945257))
16+
* **internal:** reduce CI branch coverage ([7c6570e](https://github.com/lumalabs/lumaai-python/commit/7c6570e1e1a9cd62d67017d62af8375b8eb6a145))
17+
* **internal:** slight transform perf improvement ([#149](https://github.com/lumalabs/lumaai-python/issues/149)) ([b95d415](https://github.com/lumalabs/lumaai-python/commit/b95d415fb6f3a92b90e78044c3756b84611a9179))
18+
* **tests:** improve enum examples ([#151](https://github.com/lumalabs/lumaai-python/issues/151)) ([dc358d1](https://github.com/lumalabs/lumaai-python/commit/dc358d17dc810dc8e1de849679a618c61a626cd5))
19+
320
## 1.7.2 (2025-04-04)
421

522
Full Changelog: [v1.7.1...v1.7.2](https://github.com/lumalabs/lumaai-python/compare/v1.7.1...v1.7.2)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "lumaai"
3-
version = "1.7.2"
3+
version = "1.7.3"
44
description = "The official Python library for the lumaai API"
55
dynamic = ["readme"]
66
license = "Apache-2.0"

src/lumaai/_utils/_transform.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
import pathlib
66
from typing import Any, Mapping, TypeVar, cast
77
from datetime import date, datetime
8-
from typing_extensions import Literal, get_args, override, get_type_hints
8+
from typing_extensions import Literal, get_args, override, get_type_hints as _get_type_hints
99

1010
import anyio
1111
import pydantic
1212

1313
from ._utils import (
1414
is_list,
15+
is_given,
16+
lru_cache,
1517
is_mapping,
1618
is_iterable,
1719
)
@@ -108,6 +110,7 @@ class Params(TypedDict, total=False):
108110
return cast(_T, transformed)
109111

110112

113+
@lru_cache(maxsize=8096)
111114
def _get_annotated_type(type_: type) -> type | None:
112115
"""If the given type is an `Annotated` type then it is returned, if not `None` is returned.
113116
@@ -142,6 +145,10 @@ def _maybe_transform_key(key: str, type_: type) -> str:
142145
return key
143146

144147

148+
def _no_transform_needed(annotation: type) -> bool:
149+
return annotation == float or annotation == int
150+
151+
145152
def _transform_recursive(
146153
data: object,
147154
*,
@@ -184,6 +191,15 @@ def _transform_recursive(
184191
return cast(object, data)
185192

186193
inner_type = extract_type_arg(stripped_type, 0)
194+
if _no_transform_needed(inner_type):
195+
# for some types there is no need to transform anything, so we can get a small
196+
# perf boost from skipping that work.
197+
#
198+
# but we still need to convert to a list to ensure the data is json-serializable
199+
if is_list(data):
200+
return data
201+
return list(data)
202+
187203
return [_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]
188204

189205
if is_union_type(stripped_type):
@@ -245,6 +261,11 @@ def _transform_typeddict(
245261
result: dict[str, object] = {}
246262
annotations = get_type_hints(expected_type, include_extras=True)
247263
for key, value in data.items():
264+
if not is_given(value):
265+
# we don't need to include `NotGiven` values here as they'll
266+
# be stripped out before the request is sent anyway
267+
continue
268+
248269
type_ = annotations.get(key)
249270
if type_ is None:
250271
# we do not have a type annotation for this field, leave it as is
@@ -332,6 +353,15 @@ async def _async_transform_recursive(
332353
return cast(object, data)
333354

334355
inner_type = extract_type_arg(stripped_type, 0)
356+
if _no_transform_needed(inner_type):
357+
# for some types there is no need to transform anything, so we can get a small
358+
# perf boost from skipping that work.
359+
#
360+
# but we still need to convert to a list to ensure the data is json-serializable
361+
if is_list(data):
362+
return data
363+
return list(data)
364+
335365
return [await _async_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]
336366

337367
if is_union_type(stripped_type):
@@ -393,10 +423,25 @@ async def _async_transform_typeddict(
393423
result: dict[str, object] = {}
394424
annotations = get_type_hints(expected_type, include_extras=True)
395425
for key, value in data.items():
426+
if not is_given(value):
427+
# we don't need to include `NotGiven` values here as they'll
428+
# be stripped out before the request is sent anyway
429+
continue
430+
396431
type_ = annotations.get(key)
397432
if type_ is None:
398433
# we do not have a type annotation for this field, leave it as is
399434
result[key] = value
400435
else:
401436
result[_maybe_transform_key(key, type_)] = await _async_transform_recursive(value, annotation=type_)
402437
return result
438+
439+
440+
@lru_cache(maxsize=8096)
441+
def get_type_hints(
442+
obj: Any,
443+
globalns: dict[str, Any] | None = None,
444+
localns: Mapping[str, Any] | None = None,
445+
include_extras: bool = False,
446+
) -> dict[str, Any]:
447+
return _get_type_hints(obj, globalns=globalns, localns=localns, include_extras=include_extras)

src/lumaai/_utils/_typing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
get_origin,
1414
)
1515

16+
from ._utils import lru_cache
1617
from .._types import InheritsGeneric
1718
from .._compat import is_union as _is_union
1819

@@ -66,6 +67,7 @@ def is_type_alias_type(tp: Any, /) -> TypeIs[typing_extensions.TypeAliasType]:
6667

6768

6869
# Extracts T from Annotated[T, ...] or from Required[Annotated[T, ...]]
70+
@lru_cache(maxsize=8096)
6971
def strip_annotated_type(typ: type) -> type:
7072
if is_required_type(typ) or is_annotated_type(typ):
7173
return strip_annotated_type(cast(type, get_args(typ)[0]))

src/lumaai/_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__ = "lumaai"
4-
__version__ = "1.7.2" # x-release-please-version
4+
__version__ = "1.7.3" # x-release-please-version

tests/api_resources/generations/test_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_method_create(self, client: LumaAI) -> None:
2525
@parametrize
2626
def test_method_create_with_all_params(self, client: LumaAI) -> None:
2727
image = client.generations.image.create(
28-
aspect_ratio="1:1",
28+
aspect_ratio="16:9",
2929
callback_url="https://example.com",
3030
character_ref={"identity0": {"images": ["https://example.com"]}},
3131
generation_type="image",
@@ -82,7 +82,7 @@ async def test_method_create(self, async_client: AsyncLumaAI) -> None:
8282
@parametrize
8383
async def test_method_create_with_all_params(self, async_client: AsyncLumaAI) -> None:
8484
image = await async_client.generations.image.create(
85-
aspect_ratio="1:1",
85+
aspect_ratio="16:9",
8686
callback_url="https://example.com",
8787
character_ref={"identity0": {"images": ["https://example.com"]}},
8888
generation_type="image",

tests/api_resources/generations/test_video.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_method_create(self, client: LumaAI) -> None:
2525
@parametrize
2626
def test_method_create_with_all_params(self, client: LumaAI) -> None:
2727
video = client.generations.video.create(
28-
aspect_ratio="1:1",
28+
aspect_ratio="16:9",
2929
callback_url="https://example.com",
3030
duration="5s",
3131
generation_type="video",
@@ -78,7 +78,7 @@ async def test_method_create(self, async_client: AsyncLumaAI) -> None:
7878
@parametrize
7979
async def test_method_create_with_all_params(self, async_client: AsyncLumaAI) -> None:
8080
video = await async_client.generations.video.create(
81-
aspect_ratio="1:1",
81+
aspect_ratio="16:9",
8282
callback_url="https://example.com",
8383
duration="5s",
8484
generation_type="video",

tests/api_resources/test_generations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_method_create(self, client: LumaAI) -> None:
2828
@parametrize
2929
def test_method_create_with_all_params(self, client: LumaAI) -> None:
3030
generation = client.generations.create(
31-
aspect_ratio="1:1",
31+
aspect_ratio="16:9",
3232
callback_url="https://example.com",
3333
duration="5s",
3434
generation_type="video",
@@ -287,7 +287,7 @@ async def test_method_create(self, async_client: AsyncLumaAI) -> None:
287287
@parametrize
288288
async def test_method_create_with_all_params(self, async_client: AsyncLumaAI) -> None:
289289
generation = await async_client.generations.create(
290-
aspect_ratio="1:1",
290+
aspect_ratio="16:9",
291291
callback_url="https://example.com",
292292
duration="5s",
293293
generation_type="video",

0 commit comments

Comments
 (0)