Skip to content
Open
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
4 changes: 3 additions & 1 deletion scripts/generate_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ def generate_method_signature(

for param in optional_params:
default = param.get("default")
if default is None:
# A spec default of {} or [] would become a shared mutable default
# (ruff B006). None omits the field, so the API applies that default.
if default is None or isinstance(default, (dict, list)):
default_str = "None"
elif isinstance(default, str):
default_str = f'"{default}"'
Expand Down
12 changes: 6 additions & 6 deletions src/late/resources/_generated/automations.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def install_automation_template(
template_id: str,
*,
idempotency_key: str | None = None,
inputs: dict[str, Any] | None = {},
inputs: dict[str, Any] | None = None,
targets: list[dict[str, Any]] | None = None,
status: str | None = "paused",
) -> dict[str, Any]:
Expand Down Expand Up @@ -299,7 +299,7 @@ def install_shared_automation_template(
share_token: str,
*,
idempotency_key: str | None = None,
inputs: dict[str, Any] | None = {},
inputs: dict[str, Any] | None = None,
targets: list[dict[str, Any]] | None = None,
status: str | None = "paused",
) -> dict[str, Any]:
Expand Down Expand Up @@ -327,7 +327,7 @@ def install_zernio_automation_template(
template_id: str,
*,
idempotency_key: str | None = None,
inputs: dict[str, Any] | None = {},
inputs: dict[str, Any] | None = None,
targets: list[dict[str, Any]] | None = None,
status: str | None = "paused",
) -> dict[str, Any]:
Expand Down Expand Up @@ -638,7 +638,7 @@ async def ainstall_automation_template(
template_id: str,
*,
idempotency_key: str | None = None,
inputs: dict[str, Any] | None = {},
inputs: dict[str, Any] | None = None,
targets: list[dict[str, Any]] | None = None,
status: str | None = "paused",
) -> dict[str, Any]:
Expand Down Expand Up @@ -668,7 +668,7 @@ async def ainstall_shared_automation_template(
share_token: str,
*,
idempotency_key: str | None = None,
inputs: dict[str, Any] | None = {},
inputs: dict[str, Any] | None = None,
targets: list[dict[str, Any]] | None = None,
status: str | None = "paused",
) -> dict[str, Any]:
Expand Down Expand Up @@ -698,7 +698,7 @@ async def ainstall_zernio_automation_template(
template_id: str,
*,
idempotency_key: str | None = None,
inputs: dict[str, Any] | None = {},
inputs: dict[str, Any] | None = None,
targets: list[dict[str, Any]] | None = None,
status: str | None = "paused",
) -> dict[str, Any]:
Expand Down
55 changes: 55 additions & 0 deletions tests/test_generated_mutable_defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""Spec defaults of {} or [] must not become shared mutable kwarg defaults."""

import importlib
from pathlib import Path
from unittest.mock import Mock


def test_empty_object_and_array_defaults_are_omitted(monkeypatch):
monkeypatch.syspath_prepend(str(Path(__file__).resolve().parents[1] / "scripts"))
generator = importlib.import_module("generate_resources")
operation = {
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"inputs": {"type": "object", "default": {}},
"targets": {
"type": "array",
"items": {"type": "string"},
"default": [],
},
"status": {"type": "string", "default": "paused"},
},
}
}
}
}
}
source = generator.generate_resource_class(
"probe",
[
{
"operation_id": "installTemplate",
"http_method": "post",
"path": "/v1/templates/install",
"summary": "Install template",
"description": "",
"params": generator.extract_parameters(operation, {}),
}
],
)

assert "= {}," not in source
assert "= []," not in source

namespace = {}
exec(compile(source, "<generated-probe>", "exec"), namespace)
client = Mock()
client._post = Mock(return_value={})
namespace["ProbeResource"](client).install_template()
client._post.assert_called_once_with(
"/v1/templates/install", data={"status": "paused"}
)
Loading