docstring
Official PyTorch guidance for precise, consistent, and verifiable docstrings.
- Skill Road
- docstring
Docstring is an official skill in the PyTorch repository. It helps developers and technical writers create or revise function and method documentation in the style used by the PyTorch project. According to the provider, the skill follows conventions found in central PyTorch files such as torch/_tensor_docs.py and torch/nn/functional.py. Its purpose is not to generate arbitrary product prose. It is intended to structure technical docstrings so that signatures, behavior, parameters, return values, examples, and references remain understandable to readers and usable by the project's documentation tooling.
Purpose and structure
The guide starts with a signature on the first line. That line should show the function name, positional arguments, keyword arguments, defaults, and return type, and it should not end with a period. A short behavior description follows. Depending on the function, the docstring can add mathematical formulas with the project's Sphinx notation, cross-references to classes, functions, methods, or attributes, and notes or warnings. The source therefore separates quick orientation from the details required for a dependable API reference.
Parameters and results
A central part of the skill is systematic argument documentation. Parameter names should be lowercase, types belong in parentheses, and optional values should state their default. Keyword arguments may receive a separate section when that improves readability. Return values deserve an explanation when their shape, type, or semantics are not already clear from the signature. These conventions expose assumptions that would otherwise remain implicit, including tensor shape conventions, behavior for particular data types, or the effect of a flag.
Examples and cross-references
According to the provider, examples should be included whenever they are useful. A strong example demonstrates a realistic call and can show an important variation or expected output. Cross-references connect the text to related PyTorch classes and functions. The result is a navigable reference rather than an isolated paragraph. For mathematical operations, a formula can make the relationship between the implementation and its documented behavior more precise. The skill distinguishes native Python functions from C-bound functions: for the latter pattern, documentation is attached to the bound object through the repository's designated add-documentation function.
Quality assurance and boundaries
Docstring is a writing and review guide, not an automatic proof that an implementation is correct. Before publication, authors must check that the signature, code, tests, and observed runtime behavior agree. Optional arguments, shapes and device types, edge cases, warnings, and references to renamed or removed APIs deserve particular attention. The skill points to Sphinx and reStructuredText, while the exact PyTorch version, documentation build, and local project rules remain authoritative. A model can produce plausible but incorrect technical statements, so examples should be executed or checked against tests whenever practical. Confidential source code should be processed only in an explicitly authorized workspace.
Source and classification
The primary source is https://github.com/pytorch/pytorch/tree/main/.claude/skills/docstring. The complementary official PyTorch documentation at https://docs.pytorch.org/docs/stable/notes/doc.html describes the project's documentation conventions. PyTorch is released under BSD-3-Clause. This description was reviewed on September 9, 2026. GitHub stars are not stored because the Skill model has no github_stars field. The skill is marked as compatible with Claude Code because it is published under .claude/skills. It does not replace expert review, tests, or the documentation build for the PyTorch source state being changed.
- Provider
- PyTorch
- License
- BSD-3-Clause
- Last reviewed
- 09.09.2026
Repository and documentation
Categories
Compatible with
Related guides
Guides and background related to this entry.
Set up the Fakechat plugin for Claude Code
Install the Fakechat plugin, start Claude Code with the channels flag, and test messages and files through a local browser interface.
30.09.2026
Setting up Laravel Boost
Install Laravel Boost in a Laravel application and connect it to Claude Code, Cursor, or Codex.
29.09.2026
Set up the Azure DevOps MCP Server
Start Set up the Azure DevOps MCP Server with verified links, minimal permissions, and a safe first test.
25.09.2026
Installing a Claude Code plugin
Installing a plugin from the official Anthropic marketplace – using the Code Review plugin as an example.
24.09.2026