Ctrl + k

or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/frozendict@2.4.x
tile.json

tessl/pypi-frozendict

tessl install tessl/pypi-frozendict@2.4.0

A simple immutable dictionary implementation with hashing support and performance optimizations

Agent Success

Agent success rate when using this tile

85%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.31x

Baseline

Agent success rate without this tile

65%

task.mdevals/scenario-8/

Custom Type Freezer

Build a utility that converts data structures containing custom objects into deeply frozen immutable versions. The utility should register custom conversion rules and apply them when freezing.

Requirements

Implement functionality that:

  1. Registers custom type converters for Point and Rectangle classes
  2. Converts Point instances to tuples and Rectangle instances to dicts during freezing
  3. Handles nested structures (lists/dicts) containing these custom objects
  4. Supports inverse converters to reconstruct original objects from frozen forms

Test Cases

  • Freezing {"point": Point(1, 2)} returns frozendict({"point": (1, 2)}) @test
  • Freezing {"shapes": [Rectangle(10, 20)]} returns frozendict({"shapes": ({"w": 10, "h": 20},)}) @test
  • Inverse conversion of frozendict({"point": (1, 2)}) reconstructs {"point": Point(1, 2)} @test

Implementation

@generates

API

class Point:
    """Mutable point with x, y coordinates."""
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __eq__(self, other):
        return isinstance(other, Point) and self.x == other.x and self.y == other.y


class Rectangle:
    """Mutable rectangle with width and height."""
    def __init__(self, width, height):
        self.width = width
        self.height = height

    def __eq__(self, other):
        return isinstance(other, Rectangle) and self.width == other.width and self.height == other.height


def setup_custom_converters():
    """
    Register custom type converters for Point and Rectangle classes.

    Point should convert to tuple: Point(x, y) -> (x, y)
    Rectangle should convert to dict: Rectangle(w, h) -> {"w": w, "h": h}

    Also register inverse converters for round-trip conversion.
    """
    pass


def freeze_with_custom_types(obj):
    """
    Deep freeze an object using the registered custom converters.

    Args:
        obj: The object to freeze (typically a dict or list containing custom types)

    Returns:
        A deeply frozen immutable version with custom types converted
    """
    pass

Dependencies { .dependencies }

frozendict { .dependency }

Provides immutable dictionary implementation with deep freeze functionality and custom converter registration.