Skip to content

Commit aa2173d

Browse files
stephengruppettaStephen GruppettaCopilot
authored
Sample code for: Cursor vs Windsurf: Which AI Code Editor Is Best for Python? (#766)
* Sample code for: Cursor vs Windsurf: Which AI Code Editor Is Best for Python? * Update README to clarify content description * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Stephen Gruppetta <stephen@realpython.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 027fc5d commit aa2173d

4 files changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Cursor vs Windsurf: Which AI Code Editor Is Best for Python?
2+
3+
This folder provides the prompts and Cursor/Windsurf rules files used in the Real Python tutorial [Cursor vs Windsurf: Which AI Code Editor Is Best for Python?](https://realpython.com/cursor-vs-windsurf-python/)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
globs: "**/*.py"
3+
alwaysApply: false
4+
---
5+
# Instructions
6+
- Use type hints for all functions, return values, and dataclass fields
7+
- Use `httpx.AsyncClient` for HTTP requests; do not use `requests`
8+
or `aiohttp`
9+
- Use `await asyncio.sleep()` for delays; do not use `time.sleep()`
10+
- Return dataclasses for HTTP responses, not raw dictionaries
11+
- Follow PEP 8 style conventions
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Prompts
2+
3+
Copy-paste these into Cursor and Windsurf in order while following the tutorial.
4+
5+
## 1. Set up the project
6+
7+
```
8+
Set up a Python project in this directory following standard Python
9+
packaging conventions:
10+
- Create a virtual environment
11+
- Install httpx==0.28.1 and pytest==9.0.2
12+
- Add a tests/ directory
13+
- Use the directory name as the package name
14+
- Only include the dependencies explicitly listed here
15+
```
16+
17+
## 2. Write the async fetch function
18+
19+
```
20+
Create a file called `fetcher.py` and write an async function
21+
called fetch_json that:
22+
- Takes a URL string and an optional integer max_retries (default 3)
23+
- Uses httpx.AsyncClient to fetch JSON from the URL
24+
- Retries up to max_retries times with exponential backoff (1s, 2s, 4s)
25+
on any httpx.HTTPError
26+
- Returns the JSON response as a typed dataclass called FetchResult
27+
with fields: url (str), status_code (int), and data (dict[str, Any])
28+
- Uses proper type hints throughout
29+
```
30+
31+
## 3. Generate tests
32+
33+
Before sending this prompt, open `fetcher.py` and replace
34+
`await asyncio.sleep(delay)` with `time.sleep(delay)`, then add
35+
`import time` at the top. Save the file.
36+
37+
```
38+
Create tests/test_fetcher.py with pytest tests for fetch_json that:
39+
- Test successful fetch returns correct FetchResult
40+
- Test fetch retries twice then succeeds
41+
- Test fetch raises after exhausting retries
42+
- Test two concurrent fetches complete in <4s
43+
(one with 1s+2s retry delays, one instant)
44+
- Test fetch can be cancelled during retry delay
45+
Use httpx.MockTransport for mocking.
46+
```
47+
48+
## 4. Plan-mode prompt
49+
50+
Switch each editor to its Plan mode before sending:
51+
52+
```
53+
Add a retry_budget parameter to fetch_json that limits the total
54+
cumulative wait time across all retries.
55+
```
56+
57+
## 5. Autocomplete starter snippet
58+
59+
Type this into a file and let each editor complete it:
60+
61+
```python
62+
@dataclass
63+
class RetryMetadata:
64+
attempts_made: int
65+
# ...
66+
```
67+
68+
## 6. Manual review (Windsurf Ask mode)
69+
70+
```
71+
Review fetcher.py for bugs and lint issues and summarize what you find.
72+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
trigger: glob
3+
globs: "**/*.py"
4+
---
5+
# Instructions
6+
- Use type hints for all functions, return values, and dataclass fields
7+
- Use `httpx.AsyncClient` for HTTP requests; do not use `requests` or `aiohttp`
8+
- Use `await asyncio.sleep()` for delays; do not use `time.sleep()`
9+
- Return dataclasses for HTTP responses, not raw dictionaries
10+
- Follow PEP 8 style conventions

0 commit comments

Comments
 (0)