-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Feature Request
Add support for Literal and Enum types in the Pydantic plugin.
Current State
The MVP implementation (v0.6.0) supports:
- Basic types (str, int, float, bool)
- Optional and default values
- Complex types (List, Dict, Set, Tuple)
- Existing Pydantic BaseModel instances
Requested Enhancement
Support Literal and Enum for restricted value sets:
from typing import Literal
from enum import Enum
class Status(Enum):
PENDING = "pending"
ACTIVE = "active"
CLOSED = "closed"
sw = Switcher().plug("pydantic")
@sw
def process_action(
action: Literal["create", "update", "delete"],
status: Status
):
...
# Valid calls
sw("process_action")("create", Status.ACTIVE)
sw("process_action")("update", "pending") # String coerced to enum
# Invalid - should raise ValidationError
sw("process_action")("invalid", Status.ACTIVE)Implementation Notes
- Pydantic v2 natively supports both Literal and Enum
- Should work automatically with dynamic model creation
- Test string-to-enum coercion behavior
- Ensure clear error messages for invalid values
Priority
Medium - Useful for APIs with restricted value sets.
Related
Part of the Pydantic plugin MVP+1 features discussed in initial implementation.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request