Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 3, 2025

Research options to enrich MicroPython stdlib stubs with docstrings from CPython/typeshed without overwriting MicroPython-specific documentation.

Findings

BasedPyright/Pyright Integration

  • Typeshed stubs bundled at node_modules/basedpyright/dist/typeshed/stdlib/
  • High-quality type annotations, but intentionally exclude docstrings (maintenance policy)
  • Extractable programmatically via npm package

CPython Docstring Extraction

  • Runtime introspection via inspect module provides rich documentation
  • Successfully tested on json and sys modules (41 functions extracted)

Existing Infrastructure

  • merge_docstub.py codemod handles type-rich stub merging
  • Test case typeshed_incomplete_pyi demonstrates CPython-like stub integration
  • MicroPython-specific docstrings well-maintained in RST-generated stubs

Recommendation: Hybrid Approach

Extract type information from typeshed + docstrings from CPython runtime, merge with strict preservation:

# Before: MicroPython stub
def dumps(obj) -> str: ...

# After: enriched with types + docstrings
def dumps(obj: Any, separators: tuple[str, str] | None = ...) -> str:
    """
    Serialize ``obj`` to a JSON formatted ``str``.
    
    If ``separators`` is specified, it should be a tuple of 
    (item_separator, key_separator).
    
    Note: MicroPython has limited support for some JSON features.
    """
    ...

Critical Rules:

  • NEVER overwrite MicroPython-specific docstrings
  • ADD CPython docstrings only where none exist
  • FLAG conflicts for manual review

Deliverables

Documentation (33KB)

  • docs/README_stdlib_docstrings.md - Index
  • docs/research_summary_stdlib_docstrings.md - Executive summary
  • docs/research_stdlib_docstrings.md - Technical deep-dive (13KB)
  • docs/implementation_guide_stdlib_docstrings.md - Implementation roadmap

Proof-of-Concept Scripts (tested ✅)

  • /tmp/extract_typeshed_poc.py - Extracts from basedpyright npm package
  • /tmp/extract_cpython_docstrings.py - Extracts CPython docstrings via runtime

Implementation Phases

  1. PoC ✅ Complete - Research and validation
  2. Automation - Enhance merge_docstub.py, add preservation logic (2-3 weeks)
  3. Integration - CI/CD, optional feature flag (1-2 weeks)
  4. Maintenance - Regular updates, conflict review

Decision Points

  • Approve hybrid approach?
  • Initial module scope? (recommend: json, os, sys, re)
  • Optional or default feature?
  • Authorize Phase 2 implementation?
Original prompt

This section details on the original issue you should resolve

<issue_title>Add more docstrings to stdlib stubs</issue_title>
<issue_description>reasearch to options to do this by 👍🏻

<agent_instructions>Only research and create a plan - do not start implementation yet</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 3, 2025 14:10
Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
Copilot AI changed the title [WIP] Add more docstrings to stdlib stubs Research: stdlib stub docstring enrichment from typeshed and CPython sources Nov 3, 2025
Copilot AI requested a review from Josverl November 3, 2025 14:17
Copilot finished work on behalf of Josverl November 3, 2025 14:17
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.

Add more docstrings to stdlib stubs

2 participants