Skip to content

Commit ba3a71a

Browse files
author
Saurabh Badenkal
committed
Add Learn-compatible docstring rules to SDK dev SKILL files
Add 'Docstring Type Annotations (Microsoft Learn Compatibility)' section to both SKILL.md copies with rules, correct/wrong examples to prevent the ':class:\X\ of :class:\Y\' anti-pattern from being reintroduced.
1 parent 03ce5f0 commit ba3a71a

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

  • .claude/skills/dataverse-sdk-dev
  • src/PowerPlatform/Dataverse/claude_skill/dataverse-sdk-dev

.claude/skills/dataverse-sdk-dev/SKILL.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,35 @@ Navigation property names are case-sensitive and must match the entity's `$metad
5454
9. **Document public APIs** - Add Sphinx-style docstrings with examples for public methods
5555
10. **Define __all__ in module files** - Each module declares its own exports via `__all__` (e.g., `errors.py` defines `__all__ = ["HttpError", ...]`). Package `__init__.py` files should not re-export or redefine another module's `__all__`; they use `__all__ = []` to indicate no star-import exports.
5656
11. **Run black before committing** - Always run `python -m black <changed files>` before committing. CI will reject unformatted code. Config is in `pyproject.toml` under `[tool.black]`.
57+
58+
### Docstring Type Annotations (Microsoft Learn Compatibility)
59+
60+
This SDK's API reference is published on Microsoft Learn. The Learn doc pipeline parses `:type:` and `:rtype:` directives differently from standard Sphinx -- every word between `:class:` references is treated as a separate cross-reference (`<xref:word>`). Using Sphinx-style `:class:\`list\` of :class:\`str\`` produces broken `<xref:of>` links on Learn.
61+
62+
**Rules for `:type:` and `:rtype:` directives:**
63+
64+
- Use Python bracket notation for generic types: `list[str]`, `dict[str, Any]`, `list[dict]`
65+
- Use `or` (without `:class:`) for union types: `str or None`, `dict or list[dict]`
66+
- Use bracket nesting for complex types: `collections.abc.Iterable[list[dict]]`
67+
- Use `~` prefix for SDK types to show short name: `list[~PowerPlatform.Dataverse.models.record.Record]`
68+
- `:class:` is fine for single standalone types: `:class:\`str\``, `:class:\`bool\``
69+
70+
**Never** use `:class:\`X\` of :class:\`Y\`` or `:class:\`X\` mapping :class:\`Y\` to :class:\`Z\`` -- the words `of`, `mapping`, `to` become broken `<xref:>` links.
71+
72+
**Correct examples:**
73+
74+
```rst
75+
:type data: dict or list[dict]
76+
:rtype: list[str]
77+
:rtype: collections.abc.Iterable[list[~PowerPlatform.Dataverse.models.record.Record]]
78+
:type select: list[str] or None
79+
:type columns: dict[str, typing.Any]
80+
```
81+
82+
**Wrong examples (NEVER use):**
83+
84+
```rst
85+
:type data: :class:`dict` or :class:`list` of :class:`dict`
86+
:rtype: :class:`list` of :class:`str`
87+
:type columns: :class:`dict` mapping :class:`str` to :class:`typing.Any`
88+
```

src/PowerPlatform/Dataverse/claude_skill/dataverse-sdk-dev/SKILL.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,35 @@ This skill provides guidance for developers working on the PowerPlatform Dataver
2828
9. **Document public APIs** - Add Sphinx-style docstrings with examples for public methods
2929
10. **Define __all__ in module files** - Each module declares its own exports via `__all__` (e.g., `errors.py` defines `__all__ = ["HttpError", ...]`). Package `__init__.py` files should not re-export or redefine another module's `__all__`; they use `__all__ = []` to indicate no star-import exports.
3030
11. **Run black before committing** - Always run `python -m black <changed files>` before committing. CI will reject unformatted code. Config is in `pyproject.toml` under `[tool.black]`.
31+
32+
### Docstring Type Annotations (Microsoft Learn Compatibility)
33+
34+
This SDK's API reference is published on Microsoft Learn. The Learn doc pipeline parses `:type:` and `:rtype:` directives differently from standard Sphinx -- every word between `:class:` references is treated as a separate cross-reference (`<xref:word>`). Using Sphinx-style `:class:\`list\` of :class:\`str\`` produces broken `<xref:of>` links on Learn.
35+
36+
**Rules for `:type:` and `:rtype:` directives:**
37+
38+
- Use Python bracket notation for generic types: `list[str]`, `dict[str, Any]`, `list[dict]`
39+
- Use `or` (without `:class:`) for union types: `str or None`, `dict or list[dict]`
40+
- Use bracket nesting for complex types: `collections.abc.Iterable[list[dict]]`
41+
- Use `~` prefix for SDK types to show short name: `list[~PowerPlatform.Dataverse.models.record.Record]`
42+
- `:class:` is fine for single standalone types: `:class:\`str\``, `:class:\`bool\``
43+
44+
**Never** use `:class:\`X\` of :class:\`Y\`` or `:class:\`X\` mapping :class:\`Y\` to :class:\`Z\`` -- the words `of`, `mapping`, `to` become broken `<xref:>` links.
45+
46+
**Correct examples:**
47+
48+
```rst
49+
:type data: dict or list[dict]
50+
:rtype: list[str]
51+
:rtype: collections.abc.Iterable[list[~PowerPlatform.Dataverse.models.record.Record]]
52+
:type select: list[str] or None
53+
:type columns: dict[str, typing.Any]
54+
```
55+
56+
**Wrong examples (NEVER use):**
57+
58+
```rst
59+
:type data: :class:`dict` or :class:`list` of :class:`dict`
60+
:rtype: :class:`list` of :class:`str`
61+
:type columns: :class:`dict` mapping :class:`str` to :class:`typing.Any`
62+
```

0 commit comments

Comments
 (0)