CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pydantic

Data validation using Python type hints

90

1.30x
Overview
Eval results
Files

task.mdevals/scenario-4/

User Status Manager

A system for managing user account statuses with automatic validation and JSON serialization.

Capabilities

Status validation

  • Creating a user with status "active" succeeds @test
  • Creating a user with status "suspended" succeeds @test
  • Creating a user with an invalid status like "invalid" raises a validation error @test

JSON serialization

  • Serializing a user with status "active" to JSON produces a dictionary with status value as "active" string @test
  • Serializing a user with status "suspended" to JSON produces a dictionary with status value as "suspended" string @test

User creation from dictionary

  • Creating a user from a dictionary with status "active" succeeds @test
  • Creating a user from a dictionary with status "banned" succeeds @test

Implementation

@generates

API

from enum import Enum
from typing import Dict, Any

class AccountStatus(Enum):
    """Enumeration of possible account statuses."""
    ACTIVE = "active"
    SUSPENDED = "suspended"
    BANNED = "banned"

class User:
    """
    User model with validated account status.

    When serialized to JSON/dict, the status should be represented
    as its string value (e.g., "active") rather than the enum instance.
    """
    username: str
    status: AccountStatus

    def to_dict(self) -> Dict[str, Any]:
        """
        Convert user to dictionary representation.
        Status should be serialized as its string value.
        """
        pass

Dependencies { .dependencies }

pydantic { .dependency }

Provides data validation support.

Install with Tessl CLI

npx tessl i tessl/pypi-pydantic

tile.json