extractum-skills / rules
Cursor rule44 starsChanged 10 months agoMITView on GitHub
Python type annotation standards
- Reads credentials
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository7 other files it gives its agents.
- .cursor/rules/00-project-overview.mdcCursor rule
- .cursor/rules/05-solution-design.mdcCursor rule
- .cursor/rules/10-python-standards.mdcCursor rule
- .cursor/rules/30-logging-standards.mdcCursor rule
- .cursor/rules/40-docstrings.mdcCursor rule
- .cursor/rules/50-error-handling.mdcCursor rule
- .cursor/rules/60-async-patterns.mdcCursor rule
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
- Distinctive: line 13
All functions: must have explicit parameter types and return types
- Distinctive: line 14
All variables: should have type annotations when not obvious from assignment
- Very specific: line 15
Use TypedDict for structured dictionaries
- Very specific: line 16
Use union types with | syntax (Python 3.10+)
- Very specific: line 64
Use TypedDict instead of plain dict[str, Any] for known structures:
- Very specific: line 90
Use the modern | syntax for optional and union types:
- Distinctive: line 107
Use lowercase generic types (Python 3.9+):
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 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.
Files
---
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] = {}
```
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
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.

