CodeBench: deprecated-patterns.md + inline deprecated-säännöt promptissa
Lisätty SQLAlchemy 2.0, Pydantic v2, FastAPI ja Python deprecated → modern patterniparit. Uusimmat dokumentaatiot tarkistettu 2026-04-14.
This commit is contained in:
@@ -25,6 +25,14 @@ OUTPUT FORMAT — use these exact markers to separate files:
|
|||||||
|
|
||||||
DOCUMENTATION — every file must have a one-line module docstring. Classes get a one-line docstring. Keep it zensical: say what it IS, not what it does. No filler.
|
DOCUMENTATION — every file must have a one-line module docstring. Classes get a one-line docstring. Keep it zensical: say what it IS, not what it does. No filler.
|
||||||
|
|
||||||
|
NEVER USE DEPRECATED PATTERNS:
|
||||||
|
- ✗ declarative_base() → ✓ class Base(DeclarativeBase): pass
|
||||||
|
- ✗ Column(Type) → ✓ Mapped[type] = mapped_column(Type)
|
||||||
|
- ✗ class Config: orm_mode = True → ✓ model_config = ConfigDict(from_attributes=True)
|
||||||
|
- ✗ .dict() → ✓ .model_dump()
|
||||||
|
- ✗ Optional[str] → ✓ str | None
|
||||||
|
- ✗ session.query(Model).all() → ✓ session.execute(select(Model)).scalars().all()
|
||||||
|
|
||||||
RULES:
|
RULES:
|
||||||
- Follow the REFERENCE IMPLEMENTATION patterns exactly
|
- Follow the REFERENCE IMPLEMENTATION patterns exactly
|
||||||
- SQLAlchemy 2.0: DeclarativeBase + Mapped + mapped_column (not Column())
|
- SQLAlchemy 2.0: DeclarativeBase + Mapped + mapped_column (not Column())
|
||||||
|
|||||||
31
kipina-codebench/prompts/deprecated-patterns.md
Normal file
31
kipina-codebench/prompts/deprecated-patterns.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
DEPRECATED PATTERNS — do NOT generate these. Use the modern alternative.
|
||||||
|
|
||||||
|
SQLAlchemy:
|
||||||
|
✗ from sqlalchemy.ext.declarative import declarative_base → ✓ from sqlalchemy.orm import DeclarativeBase
|
||||||
|
✗ Base = declarative_base() → ✓ class Base(DeclarativeBase): pass
|
||||||
|
✗ Column(Integer, primary_key=True) → ✓ Mapped[int] = mapped_column(primary_key=True)
|
||||||
|
✗ Column(String(255)) → ✓ Mapped[str] = mapped_column(String(255))
|
||||||
|
✗ session.query(User).filter_by(name="x").all() → ✓ session.execute(select(User).filter_by(name="x")).scalars().all()
|
||||||
|
✗ session.query(User).get(5) → ✓ session.get(User, 5)
|
||||||
|
✗ MetaData(bind=engine) → ✓ metadata.create_all(engine)
|
||||||
|
|
||||||
|
Pydantic:
|
||||||
|
✗ class Config: orm_mode = True → ✓ model_config = ConfigDict(from_attributes=True)
|
||||||
|
✗ .dict() → ✓ .model_dump()
|
||||||
|
✗ .json() → ✓ .model_dump_json()
|
||||||
|
✗ parse_obj() → ✓ model_validate()
|
||||||
|
✗ @validator → ✓ @field_validator
|
||||||
|
✗ @root_validator → ✓ @model_validator
|
||||||
|
✗ Optional[str] (auto-None in v1) → ✓ str | None = None (explicit default in v2)
|
||||||
|
✗ ConstrainedInt → ✓ Annotated[int, Field(ge=0)]
|
||||||
|
|
||||||
|
FastAPI:
|
||||||
|
✗ status_code=201 → ✓ status_code=status.HTTP_201_CREATED (readable)
|
||||||
|
✗ Manual exception strings → ✓ HTTPException(status_code=404, detail="Not found")
|
||||||
|
✗ .dict() in handlers → ✓ .model_dump() (Pydantic v2)
|
||||||
|
|
||||||
|
Python:
|
||||||
|
✗ Optional[str] → ✓ str | None (PEP 604, Python 3.10+)
|
||||||
|
✗ List[str] → ✓ list[str] (PEP 585, Python 3.9+)
|
||||||
|
✗ Dict[str, int] → ✓ dict[str, int]
|
||||||
|
✗ Tuple[int, ...] → ✓ tuple[int, ...]
|
||||||
Reference in New Issue
Block a user