Skip to content

Commit 3a41897

Browse files
mikipaletclaude
andcommitted
fix: resolve ruff linting errors in generated resources
- Move datetime import into TYPE_CHECKING block in generated resources - Fix unused params variable in POST methods that don't use query params - Fix import sorting order in resources/__init__.py - Remove unused sys import from mcp/config.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c2678c2 commit 3a41897

5 files changed

Lines changed: 51 additions & 29 deletions

File tree

‎scripts/generate_resources.py‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,22 @@ def generate_method_body(
260260
)
261261
path_expr = f'f"{path_formatted}"'
262262

263+
# Determine if we need query params based on HTTP method
264+
# GET and DELETE use query params; POST/PUT/PATCH typically use body
265+
use_query_params = http_method.upper() in ("GET", "DELETE") and query_params
266+
use_body_params = http_method.upper() in ("POST", "PUT", "PATCH") and body_params
267+
# POST can also have query params in URL
268+
use_query_on_post = http_method.upper() in ("POST", "PUT", "PATCH") and query_params and not body_params
269+
263270
# Build params dict if needed
264-
if query_params:
271+
if use_query_params or use_query_on_post:
265272
lines.append(" params = self._build_params(")
266273
for p in query_params:
267274
lines.append(f" {p['name']}={p['name']},")
268275
lines.append(" )")
269276

270277
# Build payload dict if needed
271-
if body_params:
278+
if use_body_params:
272279
lines.append(" payload = self._build_payload(")
273280
for p in body_params:
274281
lines.append(f" {p['name']}={p['name']},")
@@ -288,6 +295,8 @@ def generate_method_body(
288295
else: # POST, PUT, PATCH
289296
if body_params:
290297
lines.append(f" return {await_prefix}self._client.{client_method}({path_expr}, data=payload)")
298+
elif query_params:
299+
lines.append(f" return {await_prefix}self._client.{client_method}({path_expr}, params=params)")
291300
else:
292301
lines.append(f" return {await_prefix}self._client.{client_method}({path_expr})")
293302

@@ -302,6 +311,13 @@ def generate_resource_class(
302311
class_name = "".join(word.title() for word in resource_name.split("_")) + "Resource"
303312
description = RESOURCE_DESCRIPTIONS.get(resource_name, f"{resource_name} operations")
304313

314+
# Check if any operation uses datetime type
315+
uses_datetime = any(
316+
"datetime" in p.get("type", "")
317+
for op in operations
318+
for p in op.get("params", [])
319+
)
320+
305321
lines = [
306322
'"""',
307323
f"Auto-generated {resource_name} resource.",
@@ -315,7 +331,17 @@ def generate_resource_class(
315331
"from typing import TYPE_CHECKING, Any",
316332
"",
317333
"if TYPE_CHECKING:",
318-
" from ..client.base import BaseClient",
334+
]
335+
336+
# Add datetime import inside TYPE_CHECKING block if needed
337+
if uses_datetime:
338+
lines.append(" from datetime import datetime")
339+
lines.append("")
340+
lines.append(" from ..client.base import BaseClient")
341+
else:
342+
lines.append(" from ..client.base import BaseClient")
343+
344+
lines.extend([
319345
"",
320346
"",
321347
f"class {class_name}:",
@@ -348,7 +374,7 @@ def generate_resource_class(
348374
" else:",
349375
" result[to_camel(k)] = v",
350376
" return result",
351-
]
377+
])
352378

353379
# Generate sync methods
354380
for op in operations:

‎src/late/mcp/config.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Configuration management for Late MCP HTTP server."""
22

33
import os
4-
import sys
54
from dataclasses import dataclass
65

76
from late.mcp.constants import (

‎src/late/resources/__init__.py‎

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@
55
Auto-generated resources are used for additional endpoints.
66
"""
77

8-
# Manual resources (with Pydantic model validation)
9-
from .accounts import AccountsResource
10-
from .analytics import AnalyticsResource
11-
from .media import MediaResource
12-
from .posts import PostsResource
13-
from .profiles import ProfilesResource
14-
from .queue import QueueResource
15-
from .tools import ToolsResource
16-
from .users import UsersResource
17-
18-
# Auto-generated resources (additional endpoints)
198
from ._generated.account_groups import AccountGroupsResource
209
from ._generated.api_keys import ApiKeysResource
2110
from ._generated.connect import ConnectResource
@@ -24,24 +13,30 @@
2413
from ._generated.reddit import RedditResource
2514
from ._generated.usage import UsageResource
2615
from ._generated.webhooks import WebhooksResource
16+
from .accounts import AccountsResource
17+
from .analytics import AnalyticsResource
18+
from .media import MediaResource
19+
from .posts import PostsResource
20+
from .profiles import ProfilesResource
21+
from .queue import QueueResource
22+
from .tools import ToolsResource
23+
from .users import UsersResource
2724

2825
__all__ = [
29-
# Manual resources
26+
"AccountGroupsResource",
3027
"AccountsResource",
3128
"AnalyticsResource",
32-
"MediaResource",
33-
"PostsResource",
34-
"ProfilesResource",
35-
"QueueResource",
36-
"ToolsResource",
37-
"UsersResource",
38-
# Auto-generated resources
39-
"AccountGroupsResource",
4029
"ApiKeysResource",
4130
"ConnectResource",
4231
"InvitesResource",
4332
"LogsResource",
33+
"MediaResource",
34+
"PostsResource",
35+
"ProfilesResource",
36+
"QueueResource",
4437
"RedditResource",
38+
"ToolsResource",
4539
"UsageResource",
40+
"UsersResource",
4641
"WebhooksResource",
4742
]

‎src/late/resources/_generated/connect.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def complete_telegram_connect(self, code: str) -> dict[str, Any]:
192192
params = self._build_params(
193193
code=code,
194194
)
195-
return self._client._patch("/v1/connect/telegram")
195+
return self._client._patch("/v1/connect/telegram", params=params)
196196

197197
def update_facebook_page(self, account_id: str, selected_page_id: str) -> dict[str, Any]:
198198
"""Update selected Facebook page for a connected account"""
@@ -384,7 +384,7 @@ async def acomplete_telegram_connect(self, code: str) -> dict[str, Any]:
384384
params = self._build_params(
385385
code=code,
386386
)
387-
return await self._client._apatch("/v1/connect/telegram")
387+
return await self._client._apatch("/v1/connect/telegram", params=params)
388388

389389
async def aupdate_facebook_page(self, account_id: str, selected_page_id: str) -> dict[str, Any]:
390390
"""Update selected Facebook page for a connected account (async)"""

‎src/late/resources/_generated/posts.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from typing import TYPE_CHECKING, Any
1111

1212
if TYPE_CHECKING:
13+
from datetime import datetime
14+
1315
from ..client.base import BaseClient
1416

1517

@@ -97,7 +99,7 @@ def bulk_upload_posts(self, *, dry_run: bool | None = False) -> dict[str, Any]:
9799
params = self._build_params(
98100
dry_run=dry_run,
99101
)
100-
return self._client._post("/v1/posts/bulk-upload")
102+
return self._client._post("/v1/posts/bulk-upload", params=params)
101103

102104
def retry_post(self, post_id: str) -> dict[str, Any]:
103105
"""Retry publishing a failed or partial post"""
@@ -156,7 +158,7 @@ async def abulk_upload_posts(self, *, dry_run: bool | None = False) -> dict[str,
156158
params = self._build_params(
157159
dry_run=dry_run,
158160
)
159-
return await self._client._apost("/v1/posts/bulk-upload")
161+
return await self._client._apost("/v1/posts/bulk-upload", params=params)
160162

161163
async def aretry_post(self, post_id: str) -> dict[str, Any]:
162164
"""Retry publishing a failed or partial post (async)"""

0 commit comments

Comments
 (0)