Skip to content

feat: add docstring enrichment, default values, re-exports#2592

Draft
andeplane wants to merge 1 commit into
001-pr2-python-schema-extended-typesfrom
001-pr3-python-schema-docstring-defaults
Draft

feat: add docstring enrichment, default values, re-exports#2592
andeplane wants to merge 1 commit into
001-pr2-python-schema-extended-typesfrom
001-pr3-python-schema-docstring-defaults

Conversation

@andeplane
Copy link
Copy Markdown
Contributor

Summary

  • _parse_docstring: parses Google-style docstrings via griffe to populate description on schema properties; appends a cognite-query-id guidance suffix to DataFrame params; returns ErrorResult for unknown docstring params
  • _apply_default_value: coerces ast.unparse strings to correct Python types (str via literal_eval, int/float cast, bool via == "True"); rejects defaults for list and non-primitive types
  • Re-exports extract_function_schema, SchemaResult, ErrorResult from cognite.client._api.ai

Changes

  • cognite/client/_api/ai/python_schema.py_parse_docstring (full), _apply_default_value, wired into _parse_single_annotation
  • cognite/client/_api/ai/__init__.py — re-exports
  • tests/tests_unit/test_api/test_python_schema.py — 14 new tests (@pytest.mark.us3)

Test plan

  • pytest tests/tests_unit/test_api/test_python_schema.py — all 46 green
  • Coverage ≥ 95% for python_schema.py (actual: 98%)
  • mypy cognite/client/_api/ai/python_schema.py — clean
  • ruff check cognite/client/_api/ai/python_schema.py — clean

Stack

  • PR 1/3 — primitive types + validation
  • PR 2/3 — NodeId, datetime, DataFrame, list types ← base
  • PR 3/3 (this PR) — docstring enrichment, default values, re-exports

🤖 Generated with Claude Code

Completes the extract_function_schema feature:
- _parse_docstring: parses Google-style docstrings via griffe to set
  description fields; appends cognite-query-id guidance suffix to
  DataFrame params; raises ValueError for unknown docstring params
- _apply_default_value: coerces ast.unparse'd defaults to the correct
  Python type (str via literal_eval, int/float cast, bool via == "True")
- _parse_single_annotation: wired to apply defaults for all param types
- __init__.py: re-exports extract_function_schema, SchemaResult, ErrorResult

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant