docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a notification parser that can deserialize notification data from JSON into Python objects, where notifications can be of different types (email, SMS, or push notifications).
Your implementation should:
Define three notification classes:
EmailNotification with fields: recipient (str), subject (str), body (str)SMSNotification with fields: phone_number (str), message (str)PushNotification with fields: device_id (str), title (str), message (str), badge_count (optional int)Implement a parse_notification(data: dict) -> Union[EmailNotification, SMSNotification, PushNotification] function that:
Implement a parse_notification_batch(data: list) -> list function that:
Handle optional fields gracefully (like badge_count in push notifications)
from typing import Union, Optional
from dataclasses import dataclass
@dataclass
class EmailNotification:
recipient: str
subject: str
body: str
@dataclass
class SMSNotification:
phone_number: str
message: str
@dataclass
class PushNotification:
device_id: str
title: str
message: str
badge_count: Optional[int] = None
def parse_notification(data: dict) -> Union[EmailNotification, SMSNotification, PushNotification]:
"""Parse a single notification from dictionary data."""
pass
def parse_notification_batch(data: list) -> list:
"""Parse a batch of notifications from list of dictionaries."""
passProvides JSON serialization and deserialization support with type handling.