Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.0.0-alpha.2"
".": "1.0.0-alpha.3"
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 1.0.0-alpha.3 (2025-04-09)

Full Changelog: [v1.0.0-alpha.2...v1.0.0-alpha.3](https://github.com/hubmapconsortium/search-python-sdk/compare/v1.0.0-alpha.2...v1.0.0-alpha.3)

### Chores

* **internal:** remove trailing character ([#20](https://github.com/hubmapconsortium/search-python-sdk/issues/20)) ([eba7907](https://github.com/hubmapconsortium/search-python-sdk/commit/eba7907ee5740d1280a2e8644505539d7e0f2bd2))
* **internal:** slight transform perf improvement ([#23](https://github.com/hubmapconsortium/search-python-sdk/issues/23)) ([4605f8b](https://github.com/hubmapconsortium/search-python-sdk/commit/4605f8b1836a291ab658811a196cb46a3df818b0))

## 1.0.0-alpha.2 (2025-04-03)

Full Changelog: [v1.0.0-alpha.1...v1.0.0-alpha.2](https://github.com/hubmapconsortium/search-python-sdk/compare/v1.0.0-alpha.1...v1.0.0-alpha.2)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "hubmap_search_sdk"
version = "1.0.0-alpha.2"
version = "1.0.0-alpha.3"
description = "The official Python library for the hubmap-search-sdk API"
dynamic = ["readme"]
license = "MIT"
Expand Down
22 changes: 22 additions & 0 deletions src/hubmap_search_sdk/_utils/_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ def _maybe_transform_key(key: str, type_: type) -> str:
return key


def _no_transform_needed(annotation: type) -> bool:
return annotation == float or annotation == int


def _transform_recursive(
data: object,
*,
Expand Down Expand Up @@ -184,6 +188,15 @@ def _transform_recursive(
return cast(object, data)

inner_type = extract_type_arg(stripped_type, 0)
if _no_transform_needed(inner_type):
# for some types there is no need to transform anything, so we can get a small
# perf boost from skipping that work.
#
# but we still need to convert to a list to ensure the data is json-serializable
if is_list(data):
return data
return list(data)

return [_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]

if is_union_type(stripped_type):
Expand Down Expand Up @@ -332,6 +345,15 @@ async def _async_transform_recursive(
return cast(object, data)

inner_type = extract_type_arg(stripped_type, 0)
if _no_transform_needed(inner_type):
# for some types there is no need to transform anything, so we can get a small
# perf boost from skipping that work.
#
# but we still need to convert to a list to ensure the data is json-serializable
if is_list(data):
return data
return list(data)

return [await _async_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]

if is_union_type(stripped_type):
Expand Down
2 changes: 1 addition & 1 deletion src/hubmap_search_sdk/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "hubmap_search_sdk"
__version__ = "1.0.0-alpha.2" # x-release-please-version
__version__ = "1.0.0-alpha.3" # x-release-please-version
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ def test_get_platform(self) -> None:
import threading

from hubmap_search_sdk._utils import asyncify
from hubmap_search_sdk._base_client import get_platform
from hubmap_search_sdk._base_client import get_platform

async def test_main() -> None:
result = await asyncify(get_platform)()
Expand Down
12 changes: 12 additions & 0 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,15 @@ async def test_base64_file_input(use_async: bool) -> None:
assert await transform({"foo": io.BytesIO(b"Hello, world!")}, TypedDictBase64Input, use_async) == {
"foo": "SGVsbG8sIHdvcmxkIQ=="
} # type: ignore[comparison-overlap]


@parametrize
@pytest.mark.asyncio
async def test_transform_skipping(use_async: bool) -> None:
# lists of ints are left as-is
data = [1, 2, 3]
assert await transform(data, List[int], use_async) is data

# iterables of ints are converted to a list
data = iter([1, 2, 3])
assert await transform(data, Iterable[int], use_async) == [1, 2, 3]