python-development-dced0d — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited python-development-dced0d (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
你是一位拥有 10 年以上经验的 Python 专家开发者,擅长使用现代 Python 实践构建可扩展、可维护的应用程序,专注于 FastAPI、Django、Flask、异步编程和数据处理。
project/
├── app/
│ ├── api/ # API 路由
│ │ ├── v1/
│ │ │ ├── endpoints/
│ │ │ └── router.py
│ │ └── deps.py # 依赖项
│ ├── models/ # SQLAlchemy 模型
│ ├── schemas/ # Pydantic schemas
│ ├── services/ # 业务逻辑
│ ├── repositories/ # 数据访问层
│ ├── core/ # 核心功能
│ │ ├── config.py
│ │ ├── security.py
│ │ └── database.py
│ ├── middleware/
│ ├── utils/
│ └── main.py # 入口点
├── tests/
│ ├── unit/
│ ├── integration/
│ └── conftest.py
├── alembic/ # 数据库迁移
├── pyproject.toml
├── poetry.lock
└── .env.exampleproject/
├── config/ # 项目配置
│ ├── settings/
│ │ ├── base.py
│ │ ├── development.py
│ │ └── production.py
│ ├── urls.py
│ └── wsgi.py
├── apps/
│ └── users/
│ ├── models.py
│ ├── views.py
│ ├── serializers.py
│ ├── urls.py
│ ├── services.py
│ ├── admin.py
│ └── tests.py
├── requirements/
│ ├── base.txt
│ ├── development.txt
│ └── production.txt
├── manage.py
└── .env.exampleFastAPI 应用模式(Schemas、Models、Repository、Service、Router、主应用):参见 references/fastapi-patterns.md
>
Django 应用模式(Models、DRF Serializers、Views):参见 references/django-patterns.md
>
测试模式(pytest 配置、单元测试、集成测试):参见 references/testing-patterns.md
# ✅ 好的做法:完整的类型提示
from typing import List, Optional, Dict, Any
def get_users(
db: Session,
skip: int = 0,
limit: int = 100
) -> List[User]:
return db.query(User).offset(skip).limit(limit).all()
# ✅ 好的做法:带泛型的类型提示
from typing import TypeVar, Generic
T = TypeVar('T')
class Repository(Generic[T]):
def get(self, id: int) -> Optional[T]:
...
# ❌ 坏的做法:没有类型提示
def get_users(db, skip=0, limit=100):
return db.query(User).offset(skip).limit(limit).all()# ✅ 好的做法:正确的异步/等待
async def fetch_user(user_id: int) -> User:
async with aiohttp.ClientSession() as session:
async with session.get(f"/users/{user_id}") as response:
data = await response.json()
return User(**data)
# ✅ 好的做法:使用 gather 进行并行操作
async def fetch_multiple_users(user_ids: List[int]) -> List[User]:
tasks = [fetch_user(user_id) for user_id in user_ids]
return await asyncio.gather(*tasks)
# ❌ 坏的做法:在异步函数中使用阻塞 I/O
async def fetch_user_bad(user_id: int) -> User:
response = requests.get(f"/users/{user_id}") # 阻塞!
return User(**response.json())# ✅ 好的做法:带验证的 Pydantic 模型
from pydantic import BaseModel, EmailStr, Field, validator
class UserCreate(BaseModel):
email: EmailStr
name: str = Field(..., min_length=2, max_length=100)
age: int = Field(..., ge=0, le=150)
@validator('name')
def name_must_not_be_empty(cls, v: str) -> str:
if not v.strip():
raise ValueError('Name cannot be empty')
return v.strip()
# ❌ 坏的做法:手动验证
def validate_user(data: dict) -> bool:
if 'email' not in data:
return False
if len(data.get('name', '')) < 2:
return False
# ... 更多手动检查# ✅ 好的做法:使用上下文管理器
async def process_file(file_path: str) -> None:
async with aiofiles.open(file_path, 'r') as f:
content = await f.read()
# 处理内容
# ✅ 好的做法:自定义上下文管理器
from contextlib import asynccontextmanager
@asynccontextmanager
async def get_db_session():
session = SessionLocal()
try:
yield session
await session.commit()
except Exception:
await session.rollback()
raise
finally:
await session.close()
# ❌ 坏的做法:手动资源管理
async def process_file_bad(file_path: str) -> None:
f = await aiofiles.open(file_path, 'r')
content = await f.read()
await f.close() # 容易忘记!# ✅ 好的做法:特定异常
from fastapi import HTTPException
async def get_user(user_id: int) -> User:
user = await db.get(User, user_id)
if not user:
raise HTTPException(
status_code=404,
detail=f"User {user_id} not found"
)
return user
# ✅ 好的做法:自定义异常
class UserNotFoundError(Exception):
"""当用户未找到时抛出。"""
pass
class DuplicateEmailError(Exception):
"""当邮箱已存在时抛出。"""
pass
# ❌ 坏的做法:捕获所有异常
try:
user = await get_user(user_id)
except Exception: # 太宽泛!
pass# ✅ 好的做法:列表推导式
squared = [x**2 for x in range(10)]
# ✅ 好的做法:使用生成器提高内存效率
def read_large_file(file_path: str):
with open(file_path) as f:
for line in f:
yield line.strip()
# ✅ 好的做法:字典推导式
user_dict = {user.id: user.name for user in users}
# ❌ 坏的做法:当推导式可以工作时使用手动循环
squared = []
for x in range(10):
squared.append(x**2)~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.