General
PromptBeginner5 minmarkdown
Untitled Skill
193
**⚠️ MANDATORY: All Python code must pass mypy strict mode**
Loading actions...
Main instructions and any bundled files for this skill.
TypeScript and ESLint rules that MUST be followed when creating, modifying, or reviewing any file under apps/frontend/, including .ts, .tsx, .js, and .jsx files. Also apply when discussing frontend li...
risks
⚠️ MANDATORY: All Python code must pass mypy strict mode
mypy app/ automatically before every commit# Install dev dependencies to match CI exactly
conda run -n ymb-py311 pip install -e ./backend[dev]
# Local type checking
make typecheck # Run mypy on all Python code
conda run -n ymb-py311 mypy app/ # Backend-specific type checking
# Verify environment consistency
conda run -n ymb-py311 which python
conda run -n ymb-py311 which mypy
# ✅ CORRECT: Complete type annotations
def process_articles(articles: list[Article], source_id: int) -> dict[str, int]:
result: dict[str, int] = {"processed": 0, "errors": 0}
return result
# ❌ INCORRECT: Missing type annotations
def process_articles(articles, source_id):
result = {"processed": 0, "errors": 0}
return result
# ✅ CORRECT: Proper None handling
existing_source.credibility_score = validated_source.credibility_score or 0.5
existing_source.is_active = (
validated_source.is_active if validated_source.is_active is not None else True
)
# ❌ INCORRECT: Direct assignment of Optional to non-Optional
existing_source.credibility_score = validated_source.credibility_score # May be None
# ✅ CORRECT: Explicit type annotation
cleaned: str = bleach.clean(content, tags=[], strip=True)
parsed_date: datetime = date_parser.parse(date_str)
# ❌ INCORRECT: Relies on Any inference
cleaned = bleach.clean(content, tags=[], strip=True) # Returns Any
The project uses ignore_missing_imports = true in backend/pyproject.toml:
# ✅ WORKS WITHOUT type: ignore (due to ignore_missing_imports = true)
import feedparser
entries = feedparser.parse(url).entries
# ❌ UNNECESSARY: type: ignore comment for missing imports
import feedparser # type: ignore
entries = feedparser.parse(url).entries # type: ignore
# ✅ STILL NEEDED: type: ignore for actual type issues
result: str = some_function_returning_any() # type: ignore[assignment]
| Error | Solution |
|---|---|
Function is missing a return type annotation | Add -> ReturnType or -> None |
Incompatible types in assignment | Check Optional types, use proper None handling |
Call to untyped function | Add type hints to function definition |
Need type annotation for variable | Add explicit type: var: Type = value |
Returning Any from function | Add explicit type annotation for clarity |
If mypy fails locally but passes in CI (or vice versa):
# 1. Verify environment consistency
conda run -n ymb-py311 which python
conda run -n ymb-py311 which mypy
# 2. Reinstall dependencies to match CI
conda run -n ymb-py311 pip install -e ./backend[dev]
# 3. Check for unnecessary type: ignore comments
grep -r "type: ignore" backend/app/
from typing import Any, Optional, Union, Dict, List
from sqlalchemy.orm import Session
from app.models.source import Source
All code must pass these automated checks: