init: common-skills v1

This commit is contained in:
Team
2026-03-26 21:00:51 +08:00
commit 264dacf157
16 changed files with 859 additions and 0 deletions
+68
View File
@@ -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
```