Skip to content

fix(sdk): 按 Copilot 评论修正 Python SDK(URL 编码、JSON 异常、GeneManifest 类型、sa…#18

Merged
chenchenchenchencj merged 2 commits into
masterfrom
cccc
Mar 7, 2026
Merged

fix(sdk): 按 Copilot 评论修正 Python SDK(URL 编码、JSON 异常、GeneManifest 类型、sa…#18
chenchenchenchencj merged 2 commits into
masterfrom
cccc

Conversation

@chenchenchenchencj

Copy link
Copy Markdown
Collaborator

…fe_dump、时间戳)

Made-with: Cursor

Copilot AI review requested due to automatic review settings March 7, 2026 08:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes several correctness issues in the Python SDK that were identified in a prior Copilot review. The changes cover URL encoding of query parameters, proper JSON exception handling, type accuracy of GeneManifest, safer YAML serialization, and a clean datetime import.

Changes:

  • URL encoding: Replace manual query string construction (f"{k}={v}") with a params dict passed to httpx, which handles percent-encoding automatically.
  • Type correctness: GeneManifest changed from total=False (all fields implicitly optional) to total=True with NotRequired[...] for truly optional fields, correctly reflecting the required vs. optional fields of the TypeScript Zod schema.
  • Cleanup fixes: json.JSONDecodeError handling for non-JSON responses, yaml.safe_dump instead of yaml.dump, and a clean datetime/UTC import replacing an inline __import__ hack.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/sdk/python/src/genehub_sdk/types.py GeneManifest now uses total=True + NotRequired to distinguish required vs. optional fields; imports NotRequired
packages/sdk/python/src/genehub_sdk/client.py Fixes URL encoding via params dict, adds json.JSONDecodeError guard, adds import json
packages/sdk/python/src/genehub_sdk/learning/engine.py Replaces inline __import__ datetime hack with proper module-level from datetime import UTC, datetime
packages/sdk/python/src/genehub_sdk/adapters/generic.py Switches yaml.dump to yaml.safe_dump to prevent arbitrary object serialization
packages/sdk/python/README.md Corrects the search_genes usage example to use positional arg instead of wrong keyword q=

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to +45
try:
data = resp.json()
except json.JSONDecodeError:
msg = resp.text or f"HTTP {resp.status_code}"
raise GeneHubError(msg) from None

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new json.JSONDecodeError handling path (lines 41–45) is not covered by any test. The existing test file tests/test_client.py has tests for success responses and API error responses, but no test exercises the case where the server returns a non-JSON body (e.g., an HTML 502 page). A test using httpx_mock.add_response(content=b"<html>Bad Gateway</html>", status_code=502) and asserting that GeneHubError is raised would cover this branch.

Copilot uses AI. Check for mistakes.
@chenchenchenchencj chenchenchenchencj merged commit 7754fe2 into master Mar 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants