Skip to content

existential-birds/beagle / plugins/beagle-python/skills/python-code-review

python-code-review

Unverified

Reviews Python code for type safety, async patterns, error handling, and common mistakes. Use when reviewing .py files, checking type hints, async/await usage, or exception handling.

FileKindSize
SKILL.mdskill md4.6 KB
references/async-patterns.mdmarkdown2.4 KB
references/common-mistakes.mdmarkdown2.7 KB
references/error-handling.mdmarkdown2.4 KB
references/pep8-style.mdmarkdown4.0 KB
references/type-safety.mdmarkdown1.9 KB

references/async-patterns.md

View on GitHub
# Async Patterns

## Critical Anti-Patterns

### 1. Blocking Calls in Async Functions

**Problem**: Blocks the event loop, defeats async benefits.

```python
# BAD - blocks event loop
async def fetch_data():
    response = requests.get(url)  # BLOCKING!
    time.sleep(1)  # BLOCKING!
    return response.json()

# GOOD - non-blocking
async def fetch_data():
    async with httpx.AsyncClient() as client:
        response = await client.get(url)
    await asyncio.sleep(1)
    return response.json()
```

### 2. Missing await on Coroutines

**Problem**: Coroutine never executes.

```python
# BAD - coroutine created but never awaited
async def process():
    fetch_data()  # Returns coroutine, doesn't execute!

# GOOD
async def process():
    await fetch_data()
```

### 3. Sequential Instead of Concurrent

**Problem**: Misses parallelization opportunity.

```python
# BAD - sequential (slow)
async def get_all():
    user = await get_user()
    posts = await get_posts()
    comments = await get_comments()
    return user, posts, comments

# GOOD - concurrent (fast)
async def get_all():
    user, posts, comments = await asyncio.gather(
        get_user(),
        get_posts(),
        get_comments()
    )
    return user, posts, comments
```

### 4. Missing async with for Async Context Managers

**Problem**: Resource not properly managed.

```python
# BAD
async def query():
    session = aiosqlite.connect(db)  # Not entered!
    return await session.execute(sql)

# GOOD
async def query():
    async with aiosqlite.connect(db) as session:
        return await session.execute(sql)
```

### 5. Sync File I/O in Async Context

**Problem**: File operations block event loop.

```python
# BAD - blocks event loop
async def read_config():
    with open("config.json") as f:
        return json.load(f)

# GOOD - use aiofiles
import aiofiles

async def read_config():
    async with aiofiles.open("config.json") as f:
        content = await f.read()
        return json.loads(content)

# ACCEPTABLE - for small files, run in executor
async def read_config():
    loop = asyncio.get_event_loop()
    return await loop.run_in_executor(None, load_config_sync)
```

## Review Questions

1. Are there any `requests`, `time.sleep`, or `open()` calls in async functions?
2. Is every coroutine call awaited?
3. Are independent async calls parallelized with `gather()`?
4. Are async context managers used with `async with`?
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 318kUpdated Claude CodeCodexUnverifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 318kUpdated Claude CodeCodexUnverifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 318kUpdated Claude CodeCodexUnverifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 318kUpdated Claude CodeCodexUnverifiedInstall