From 836ea6730f3902793fbd6f2c2658408f14fdd26a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 15 Apr 2026 20:31:21 +0000 Subject: [PATCH 1/3] feat(api): api update --- .stats.yml | 4 ++-- src/post_for_me/types/pinterest_configuration_dto.py | 3 +++ src/post_for_me/types/pinterest_configuration_dto_param.py | 3 +++ src/post_for_me/types/social_post.py | 2 +- src/post_for_me/types/social_post_create_params.py | 2 +- src/post_for_me/types/social_post_update_params.py | 2 +- tests/api_resources/test_social_posts.py | 4 ++++ 7 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.stats.yml b/.stats.yml index 0a2314b..55e7106 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 15 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/day-moon-development%2Fpost-for-me-d7bde21e6d3328e90ec781ff8e2629faeaae4bb5d8e0d350703326ec8aadf898.yml -openapi_spec_hash: dcb2130480c4476fe08fcb080e369ce0 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/day-moon-development%2Fpost-for-me-139771bb833a3229ac9f11c19502c246e4bcbdf6673ebcac3c8c72807eec6f4a.yml +openapi_spec_hash: 387d1ecb6860a8a67596b1066dc55ce7 config_hash: 0ec19602e41aea0526548245a59d4253 diff --git a/src/post_for_me/types/pinterest_configuration_dto.py b/src/post_for_me/types/pinterest_configuration_dto.py index ba6f082..cf9200c 100644 --- a/src/post_for_me/types/pinterest_configuration_dto.py +++ b/src/post_for_me/types/pinterest_configuration_dto.py @@ -67,3 +67,6 @@ class PinterestConfigurationDto(BaseModel): media: Optional[List[Media]] = None """Overrides the `media` from the post""" + + title: Optional[str] = None + """Overrides the `title` from the post for Pinterest""" diff --git a/src/post_for_me/types/pinterest_configuration_dto_param.py b/src/post_for_me/types/pinterest_configuration_dto_param.py index 60845c8..1f56777 100644 --- a/src/post_for_me/types/pinterest_configuration_dto_param.py +++ b/src/post_for_me/types/pinterest_configuration_dto_param.py @@ -69,3 +69,6 @@ class PinterestConfigurationDtoParam(TypedDict, total=False): media: Optional[Iterable[Media]] """Overrides the `media` from the post""" + + title: Optional[str] + """Overrides the `title` from the post for Pinterest""" diff --git a/src/post_for_me/types/social_post.py b/src/post_for_me/types/social_post.py index 9cf83cc..5dc96ba 100644 --- a/src/post_for_me/types/social_post.py +++ b/src/post_for_me/types/social_post.py @@ -167,7 +167,7 @@ class AccountConfigurationConfiguration(BaseModel): """If false Instagram video posts will only be shown in the Reels tab""" title: Optional[str] = None - """Overrides the `title` from the post""" + """Overrides the `title` from the post (Pinterest, TikTok, YouTube)""" trial_reel_type: Optional[Literal["manual", "performance"]] = None """Instagram trial reel type, when passed will be created as a trial reel. diff --git a/src/post_for_me/types/social_post_create_params.py b/src/post_for_me/types/social_post_create_params.py index d456fbf..7d86ea6 100644 --- a/src/post_for_me/types/social_post_create_params.py +++ b/src/post_for_me/types/social_post_create_params.py @@ -203,7 +203,7 @@ class AccountConfigurationConfiguration(TypedDict, total=False): """If false Instagram video posts will only be shown in the Reels tab""" title: Optional[str] - """Overrides the `title` from the post""" + """Overrides the `title` from the post (Pinterest, TikTok, YouTube)""" trial_reel_type: Optional[Literal["manual", "performance"]] """Instagram trial reel type, when passed will be created as a trial reel. diff --git a/src/post_for_me/types/social_post_update_params.py b/src/post_for_me/types/social_post_update_params.py index fa55930..468822c 100644 --- a/src/post_for_me/types/social_post_update_params.py +++ b/src/post_for_me/types/social_post_update_params.py @@ -203,7 +203,7 @@ class AccountConfigurationConfiguration(TypedDict, total=False): """If false Instagram video posts will only be shown in the Reels tab""" title: Optional[str] - """Overrides the `title` from the post""" + """Overrides the `title` from the post (Pinterest, TikTok, YouTube)""" trial_reel_type: Optional[Literal["manual", "performance"]] """Instagram trial reel type, when passed will be created as a trial reel. diff --git a/tests/api_resources/test_social_posts.py b/tests/api_resources/test_social_posts.py index b66c6b0..2398510 100644 --- a/tests/api_resources/test_social_posts.py +++ b/tests/api_resources/test_social_posts.py @@ -219,6 +219,7 @@ def test_method_create_with_all_params(self, client: PostForMe) -> None: "thumbnail_url": {}, } ], + "title": "title", }, "threads": { "caption": {}, @@ -626,6 +627,7 @@ def test_method_update_with_all_params(self, client: PostForMe) -> None: "thumbnail_url": {}, } ], + "title": "title", }, "threads": { "caption": {}, @@ -1090,6 +1092,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncPostForMe) "thumbnail_url": {}, } ], + "title": "title", }, "threads": { "caption": {}, @@ -1497,6 +1500,7 @@ async def test_method_update_with_all_params(self, async_client: AsyncPostForMe) "thumbnail_url": {}, } ], + "title": "title", }, "threads": { "caption": {}, From 897e06a740ac67aaacd96fc1c70a2cb07407d02a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 08:27:01 +0000 Subject: [PATCH 2/3] perf(client): optimize file structure copying in multipart requests --- src/post_for_me/_files.py | 56 ++++++++++++++++- src/post_for_me/_utils/__init__.py | 1 - src/post_for_me/_utils/_utils.py | 15 ----- tests/test_deepcopy.py | 58 ----------------- tests/test_files.py | 99 +++++++++++++++++++++++++++++- 5 files changed, 151 insertions(+), 78 deletions(-) delete mode 100644 tests/test_deepcopy.py diff --git a/src/post_for_me/_files.py b/src/post_for_me/_files.py index cc14c14..0fdce17 100644 --- a/src/post_for_me/_files.py +++ b/src/post_for_me/_files.py @@ -3,8 +3,8 @@ import io import os import pathlib -from typing import overload -from typing_extensions import TypeGuard +from typing import Sequence, cast, overload +from typing_extensions import TypeVar, TypeGuard import anyio @@ -17,7 +17,9 @@ HttpxFileContent, HttpxRequestFiles, ) -from ._utils import is_tuple_t, is_mapping_t, is_sequence_t +from ._utils import is_list, is_mapping, is_tuple_t, is_mapping_t, is_sequence_t + +_T = TypeVar("_T") def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]: @@ -121,3 +123,51 @@ async def async_read_file_content(file: FileContent) -> HttpxFileContent: return await anyio.Path(file).read_bytes() return file + + +def deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]]) -> _T: + """Copy only the containers along the given paths. + + Used to guard against mutation by extract_files without copying the entire structure. + Only dicts and lists that lie on a path are copied; everything else + is returned by reference. + + For example, given paths=[["foo", "files", "file"]] and the structure: + { + "foo": { + "bar": {"baz": {}}, + "files": {"file": } + } + } + The root dict, "foo", and "files" are copied (they lie on the path). + "bar" and "baz" are returned by reference (off the path). + """ + return _deepcopy_with_paths(item, paths, 0) + + +def _deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]], index: int) -> _T: + if not paths: + return item + if is_mapping(item): + key_to_paths: dict[str, list[Sequence[str]]] = {} + for path in paths: + if index < len(path): + key_to_paths.setdefault(path[index], []).append(path) + + # if no path continues through this mapping, it won't be mutated and copying it is redundant + if not key_to_paths: + return item + + result = dict(item) + for key, subpaths in key_to_paths.items(): + if key in result: + result[key] = _deepcopy_with_paths(result[key], subpaths, index + 1) + return cast(_T, result) + if is_list(item): + array_paths = [path for path in paths if index < len(path) and path[index] == ""] + + # if no path expects a list here, nothing will be mutated inside it - return by reference + if not array_paths: + return cast(_T, item) + return cast(_T, [_deepcopy_with_paths(entry, array_paths, index + 1) for entry in item]) + return item diff --git a/src/post_for_me/_utils/__init__.py b/src/post_for_me/_utils/__init__.py index 10cb66d..1c090e5 100644 --- a/src/post_for_me/_utils/__init__.py +++ b/src/post_for_me/_utils/__init__.py @@ -24,7 +24,6 @@ coerce_integer as coerce_integer, file_from_path as file_from_path, strip_not_given as strip_not_given, - deepcopy_minimal as deepcopy_minimal, get_async_library as get_async_library, maybe_coerce_float as maybe_coerce_float, get_required_header as get_required_header, diff --git a/src/post_for_me/_utils/_utils.py b/src/post_for_me/_utils/_utils.py index 63b8cd6..771859f 100644 --- a/src/post_for_me/_utils/_utils.py +++ b/src/post_for_me/_utils/_utils.py @@ -177,21 +177,6 @@ def is_iterable(obj: object) -> TypeGuard[Iterable[object]]: return isinstance(obj, Iterable) -def deepcopy_minimal(item: _T) -> _T: - """Minimal reimplementation of copy.deepcopy() that will only copy certain object types: - - - mappings, e.g. `dict` - - list - - This is done for performance reasons. - """ - if is_mapping(item): - return cast(_T, {k: deepcopy_minimal(v) for k, v in item.items()}) - if is_list(item): - return cast(_T, [deepcopy_minimal(entry) for entry in item]) - return item - - # copied from https://github.com/Rapptz/RoboDanny def human_join(seq: Sequence[str], *, delim: str = ", ", final: str = "or") -> str: size = len(seq) diff --git a/tests/test_deepcopy.py b/tests/test_deepcopy.py deleted file mode 100644 index d160965..0000000 --- a/tests/test_deepcopy.py +++ /dev/null @@ -1,58 +0,0 @@ -from post_for_me._utils import deepcopy_minimal - - -def assert_different_identities(obj1: object, obj2: object) -> None: - assert obj1 == obj2 - assert id(obj1) != id(obj2) - - -def test_simple_dict() -> None: - obj1 = {"foo": "bar"} - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - - -def test_nested_dict() -> None: - obj1 = {"foo": {"bar": True}} - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - assert_different_identities(obj1["foo"], obj2["foo"]) - - -def test_complex_nested_dict() -> None: - obj1 = {"foo": {"bar": [{"hello": "world"}]}} - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - assert_different_identities(obj1["foo"], obj2["foo"]) - assert_different_identities(obj1["foo"]["bar"], obj2["foo"]["bar"]) - assert_different_identities(obj1["foo"]["bar"][0], obj2["foo"]["bar"][0]) - - -def test_simple_list() -> None: - obj1 = ["a", "b", "c"] - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - - -def test_nested_list() -> None: - obj1 = ["a", [1, 2, 3]] - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - assert_different_identities(obj1[1], obj2[1]) - - -class MyObject: ... - - -def test_ignores_other_types() -> None: - # custom classes - my_obj = MyObject() - obj1 = {"foo": my_obj} - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - assert obj1["foo"] is my_obj - - # tuples - obj3 = ("a", "b") - obj4 = deepcopy_minimal(obj3) - assert obj3 is obj4 diff --git a/tests/test_files.py b/tests/test_files.py index 9f789a5..c70085c 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -4,7 +4,8 @@ import pytest from dirty_equals import IsDict, IsList, IsBytes, IsTuple -from post_for_me._files import to_httpx_files, async_to_httpx_files +from post_for_me._files import to_httpx_files, deepcopy_with_paths, async_to_httpx_files +from post_for_me._utils import extract_files readme_path = Path(__file__).parent.parent.joinpath("README.md") @@ -49,3 +50,99 @@ def test_string_not_allowed() -> None: "file": "foo", # type: ignore } ) + + +def assert_different_identities(obj1: object, obj2: object) -> None: + assert obj1 == obj2 + assert obj1 is not obj2 + + +class TestDeepcopyWithPaths: + def test_copies_top_level_dict(self) -> None: + original = {"file": b"data", "other": "value"} + result = deepcopy_with_paths(original, [["file"]]) + assert_different_identities(result, original) + + def test_file_value_is_same_reference(self) -> None: + file_bytes = b"contents" + original = {"file": file_bytes} + result = deepcopy_with_paths(original, [["file"]]) + assert_different_identities(result, original) + assert result["file"] is file_bytes + + def test_list_popped_wholesale(self) -> None: + files = [b"f1", b"f2"] + original = {"files": files, "title": "t"} + result = deepcopy_with_paths(original, [["files", ""]]) + assert_different_identities(result, original) + result_files = result["files"] + assert isinstance(result_files, list) + assert_different_identities(result_files, files) + + def test_nested_array_path_copies_list_and_elements(self) -> None: + elem1 = {"file": b"f1", "extra": 1} + elem2 = {"file": b"f2", "extra": 2} + original = {"items": [elem1, elem2]} + result = deepcopy_with_paths(original, [["items", "", "file"]]) + assert_different_identities(result, original) + result_items = result["items"] + assert isinstance(result_items, list) + assert_different_identities(result_items, original["items"]) + assert_different_identities(result_items[0], elem1) + assert_different_identities(result_items[1], elem2) + + def test_empty_paths_returns_same_object(self) -> None: + original = {"foo": "bar"} + result = deepcopy_with_paths(original, []) + assert result is original + + def test_multiple_paths(self) -> None: + f1 = b"file1" + f2 = b"file2" + original = {"a": f1, "b": f2, "c": "unchanged"} + result = deepcopy_with_paths(original, [["a"], ["b"]]) + assert_different_identities(result, original) + assert result["a"] is f1 + assert result["b"] is f2 + assert result["c"] is original["c"] + + def test_extract_files_does_not_mutate_original_top_level(self) -> None: + file_bytes = b"contents" + original = {"file": file_bytes, "other": "value"} + + copied = deepcopy_with_paths(original, [["file"]]) + extracted = extract_files(copied, paths=[["file"]]) + + assert extracted == [("file", file_bytes)] + assert original == {"file": file_bytes, "other": "value"} + assert copied == {"other": "value"} + + def test_extract_files_does_not_mutate_original_nested_array_path(self) -> None: + file1 = b"f1" + file2 = b"f2" + original = { + "items": [ + {"file": file1, "extra": 1}, + {"file": file2, "extra": 2}, + ], + "title": "example", + } + + copied = deepcopy_with_paths(original, [["items", "", "file"]]) + extracted = extract_files(copied, paths=[["items", "", "file"]]) + + assert extracted == [("items[][file]", file1), ("items[][file]", file2)] + assert original == { + "items": [ + {"file": file1, "extra": 1}, + {"file": file2, "extra": 2}, + ], + "title": "example", + } + assert copied == { + "items": [ + {"extra": 1}, + {"extra": 2}, + ], + "title": "example", + } From 7b2f024b2f01a8fa0fc30614ac65d3dd257e1337 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 08:27:16 +0000 Subject: [PATCH 3/3] release: 1.16.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 13 +++++++++++++ pyproject.toml | 2 +- src/post_for_me/_version.py | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 7ccfe12..bc845f3 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.15.0" + ".": "1.16.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 9787795..774f9ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## 1.16.0 (2026-04-18) + +Full Changelog: [v1.15.0...v1.16.0](https://github.com/DayMoonDevelopment/post-for-me-python/compare/v1.15.0...v1.16.0) + +### Features + +* **api:** api update ([836ea67](https://github.com/DayMoonDevelopment/post-for-me-python/commit/836ea6730f3902793fbd6f2c2658408f14fdd26a)) + + +### Performance Improvements + +* **client:** optimize file structure copying in multipart requests ([897e06a](https://github.com/DayMoonDevelopment/post-for-me-python/commit/897e06a740ac67aaacd96fc1c70a2cb07407d02a)) + ## 1.15.0 (2026-04-11) Full Changelog: [v1.14.0...v1.15.0](https://github.com/DayMoonDevelopment/post-for-me-python/compare/v1.14.0...v1.15.0) diff --git a/pyproject.toml b/pyproject.toml index 7cff57c..253c438 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "post_for_me" -version = "1.15.0" +version = "1.16.0" description = "The official Python library for the post-for-me API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/src/post_for_me/_version.py b/src/post_for_me/_version.py index 207906a..5b74e50 100644 --- a/src/post_for_me/_version.py +++ b/src/post_for_me/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "post_for_me" -__version__ = "1.15.0" # x-release-please-version +__version__ = "1.16.0" # x-release-please-version