Skip to content

Commit 5dee0d4

Browse files
committed
cursor(rules[dev-loop]) add Python docstring and doctest guidelines to development rules
1 parent 5c5d2ab commit 5dee0d4

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

.cursor/rules/dev-loop.mdc

+70
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,73 @@ Use `@git-commits.mdc` for assistance with commit message standards.
5656
## Development Loop Guidelines
5757

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

0 commit comments

Comments
 (0)