Skip to content

Commit 684ed4d

Browse files
committed
docs: add Python docstring and doctest guidelines to development rules
1 parent 1542ff6 commit 684ed4d

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

.cursor/rules/dev-loop.mdc

+71-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,78 @@ uv run py.test
5050

5151
## 6. Final Commit
5252

53-
Make a final commit with any linting/typing fixes.
54-
Use `@git-commits.mdc` for assistance with commit message standards.
53+
If all tests pass, make your final commit.
5554

5655
## Development Loop Guidelines
5756

5857
If there are any failures at any step due to your edits, fix them before proceeding to the next step.
58+
59+
## Python Code Standards
60+
61+
### Docstring Guidelines
62+
63+
For `src/**/*.py` files, follow these docstring guidelines:
64+
65+
1. **Use reStructuredText format** for all docstrings.
66+
```python
67+
"""Short description of the function or class.
68+
69+
Detailed description using reStructuredText format.
70+
71+
Parameters
72+
----------
73+
param1 : type
74+
Description of param1
75+
param2 : type
76+
Description of param2
77+
78+
Returns
79+
-------
80+
type
81+
Description of return value
82+
"""
83+
```
84+
85+
2. **Keep the main description on the first line** after the opening `"""`.
86+
87+
3. **Use NumPy docstyle** for parameter and return value documentation.
88+
89+
### Doctest Guidelines
90+
91+
For doctests in `src/**/*.py` files:
92+
93+
1. **Use narrative descriptions** for test sections rather than inline comments:
94+
```python
95+
"""Example function.
96+
97+
Examples
98+
--------
99+
Create an instance:
100+
101+
>>> obj = ExampleClass()
102+
103+
Verify a property:
104+
105+
>>> obj.property
106+
'expected value'
107+
"""
108+
```
109+
110+
2. **Move complex examples** to dedicated test files at `tests/examples/<path_to_module>/test_<example>.py` if they require elaborate setup or multiple steps.
111+
112+
3. **Utilize pytest fixtures** via `doctest_namespace` for more complex test scenarios:
113+
```python
114+
"""Example with fixture.
115+
116+
Examples
117+
--------
118+
>>> # doctest_namespace contains all pytest fixtures from conftest.py
119+
>>> example_fixture = getfixture('example_fixture')
120+
>>> example_fixture.method()
121+
'expected result'
122+
"""
123+
```
124+
125+
4. **Keep doctests simple and focused** on demonstrating usage rather than comprehensive testing.
126+
127+
5. **Add blank lines between test sections** for improved readability.

0 commit comments

Comments
 (0)