init: common-skills v1
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
---
|
||||
name: python-skill
|
||||
description: Python coding best practices and patterns. Use when writing, reviewing, or debugging Python code.
|
||||
---
|
||||
|
||||
# Python Skill
|
||||
|
||||
## Type Hints (Python 3.10+)
|
||||
|
||||
```python
|
||||
# Bad
|
||||
def process(data, callback):
|
||||
return callback(data)
|
||||
|
||||
# Good
|
||||
from typing import Callable
|
||||
|
||||
def process(data: dict, callback: Callable[[dict], str]) -> str:
|
||||
return callback(data)
|
||||
```
|
||||
|
||||
## Dataclasses Over Plain Dicts
|
||||
|
||||
```python
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class GameFrame:
|
||||
timestamp: float
|
||||
objects: list[str]
|
||||
confidence: float = 1.0
|
||||
```
|
||||
|
||||
## Context Managers for Resources
|
||||
|
||||
```python
|
||||
# Bad
|
||||
f = open("log.txt")
|
||||
data = f.read()
|
||||
f.close()
|
||||
|
||||
# Good
|
||||
with open("log.txt") as f:
|
||||
data = f.read()
|
||||
```
|
||||
|
||||
## List Comprehensions vs Loops
|
||||
|
||||
```python
|
||||
# Prefer comprehension for simple transforms
|
||||
enemies = [obj for obj in objects if obj.type == "enemy"]
|
||||
|
||||
# Use loop when logic is complex (>2 conditions)
|
||||
results = []
|
||||
for obj in objects:
|
||||
if obj.type == "enemy" and obj.visible and obj.distance < 100:
|
||||
results.append(obj.position)
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
```python
|
||||
# Be specific — never catch bare Exception silently
|
||||
try:
|
||||
frame = capture_screen()
|
||||
except ScreenCaptureError as e:
|
||||
logger.error("Screen capture failed: %s", e)
|
||||
raise
|
||||
```
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"skill_name": "python",
|
||||
"evals": [
|
||||
{
|
||||
"id": 1,
|
||||
"prompt": "What's the best way to handle file reading in Python?",
|
||||
"expected_output": "Recommends 'with' statement (context manager) for automatic resource cleanup, shows open() usage with proper mode."
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"prompt": "How should I add type hints to a Python function?",
|
||||
"expected_output": "Shows parameter type annotations, return type with ->, use of dataclasses or TypedDict for complex types."
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"prompt": "When should I use a list comprehension vs a for loop in Python?",
|
||||
"expected_output": "Recommends comprehensions for simple transforms, for loops when logic is complex (multiple conditions/side effects), with examples of each."
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user