agentleFS
extractumioextractumio/extractum-skills/.cursor/rules/20-type-annotations.mdc

extractum-skills / rules

Cursor rule47 starsChanged 10 months agoMITView on GitHub

Python type annotation standards

  • Reads credentials

The file

We split this 20-type-annotations.mdc into the rules it gives an agent

7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    All functions: must have explicit parameter types and return types

    line 13
  2. Distinctive:

    All variables: should have type annotations when not obvious from assignment

    line 14
  3. Very specific:

    Use TypedDict for structured dictionaries

    line 15
  4. Very specific:

    Use union types with | syntax (Python 3.10+)

    line 16
  5. Very specific:

    Use TypedDict instead of plain dict[str, Any] for known structures:

    line 64
  6. Very specific:

    Use the modern | syntax for optional and union types:

    line 90
  7. Distinctive:

    Use lowercase generic types (Python 3.9+):

    line 107

≈ “Common” is an estimate: at least 1 in 5 of the 7,324 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
20-type-annotations.mdc
---
description: "Python type annotation standards"
globs:
  - "**/*.py"
alwaysApply: false
priority: 15
---

# Type Annotations

## General Rules

- **All functions** must have explicit parameter types and return types
- **All variables** should have type annotations when not obvious from assignment
- Use `TypedDict` for structured dictionaries
- Use union types with `|` syntax (Python 3.10+)

---

## Function Signatures

```python
# ✅ Good - Fully typed
def setup_logging() -> logging.Logger:
    """Configure logging."""
    ...

async def run_agent(prompt: str, logger: logging.Logger) -> AgentResultSummary:
    """Run the agent with given prompt."""
    ...

def _format_result(message: ResultMessage) -> str:
    """Format result message."""
    ...

# ❌ Bad - Missing types
def setup_logging():
    ...

def run_agent(prompt, logger):
    ...
```

---

## Variable Annotations

```python
# ✅ Good - Explicit types
logs_dir: Path = Path(__file__).parent / LOGS_DIR_NAME
timestamp: str = datetime.now().strftime(LOG_TIMESTAMP_FORMAT)
api_key: str | None = os.getenv(ENV_API_KEY)
texts: list[str] = []

# ❌ Bad - No types
logs_dir = Path(__file__).parent / "logs"
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
```

---

## TypedDict for Structured Data

Use `TypedDict` instead of plain `dict[str, Any]` for known structures:

```python
# ✅ Good - TypedDict
class AgentResultSummary(TypedDict, total=False):
    """Type definition for agent execution result."""
    prompt: str
    messages: list[dict[str, Any]]
    total_cost_usd: float
    num_turns: int
    success: bool
    session_id: str
    error: str

def run_agent() -> AgentResultSummary:
    ...

# ❌ Bad - Plain dict
def run_agent() -> dict[str, Any]:
    ...
```

---

## Union Types

Use the modern `|` syntax for optional and union types:

```python
# ✅ Good - Modern syntax
api_key: str | None = os.getenv(ENV_API_KEY)
value: int | float = get_number()

# ❌ Bad - Old syntax
from typing import Optional, Union
api_key: Optional[str] = os.getenv(ENV_API_KEY)
value: Union[int, float] = get_number()
```

---

## Generic Collections

Use lowercase generic types (Python 3.9+):

```python
# ✅ Good - Lowercase generics
messages: list[str] = []
config: dict[str, Any] = {}
handlers: tuple[Handler, ...] = ()

# ❌ Bad - Capitalized (deprecated)
from typing import List, Dict, Tuple
messages: List[str] = []
config: Dict[str, Any] = {}
```

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.