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-5/

Configuration Update System

Problem Description

You need to build a simple configuration update system that maintains immutability while allowing functional-style updates. The system should track application settings that cannot be modified in place, but can be transformed into new versions with updated values.

Implement a configuration manager that:

  1. Maintains an immutable configuration dictionary
  2. Allows adding or updating configuration keys, returning a new configuration
  3. Allows removing configuration keys, returning a new configuration
  4. Provides a default value mechanism when a key is missing

Requirements

Configuration Storage

Your configuration should be stored in an immutable dictionary that cannot be modified after creation. You must use an appropriate immutable data structure for this purpose.

Update Operations

Implement the following operations, each returning a new immutable configuration:

  1. Update or add a setting: Given a key and value, create a new configuration with that key set to the value
  2. Remove a setting: Given a key, create a new configuration without that key (should raise an error if key doesn't exist)
  3. Ensure default: Given a key and default value, return the current configuration if the key exists, or a new configuration with the key set to the default if it doesn't exist

Functional Style

All operations must follow a functional programming approach:

  • Original configuration remains unchanged
  • Operations return new configurations
  • No in-place mutations

Dependencies { .dependencies }

frozendict { .dependency }

Provides immutable dictionary support.

Test Cases

Test Case 1: Basic Configuration Updates @test

File: test_config.py @test-file

Create an initial configuration with {"debug": False, "timeout": 30}.

Update the configuration to set timeout to 60. Verify:

  • New configuration has timeout equal to 60
  • New configuration has debug equal to False
  • Original configuration still has timeout equal to 30

Test Case 2: Adding New Settings @test

File: test_config.py @test-file

Create an initial configuration with {"debug": False}.

Add a new setting max_retries with value 3. Verify:

  • New configuration has both debug and max_retries keys
  • Original configuration only has debug key

Test Case 3: Removing Settings @test

File: test_config.py @test-file

Create a configuration with {"debug": True, "timeout": 30, "host": "localhost"}.

Remove the timeout setting. Verify:

  • New configuration has debug and host but not timeout
  • Attempting to remove a non-existent key port raises a KeyError

Test Case 4: Default Value Handling @test

File: test_config.py @test-file

Create a configuration with {"debug": False}.

Ensure a default value for timeout with default 30. Verify:

  • New configuration has both debug and timeout keys
  • timeout equals 30

Apply ensure default for debug with default True. Verify:

  • The returned configuration is the same as the input (no change needed)
  • debug still equals False (original value preserved)