tessl install tessl/pypi-frozendict@2.4.0A 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%
Create a configuration manager that uses immutable dictionaries with proper type checking support. The manager should leverage static type checking to ensure configuration data integrity.
Implement a configuration manager with the following features:
Create a config_manager.py file that includes:
ConfigManager class that wraps an immutable dictionaryget_config() that returns the current configuration with proper generic typingupdate_config(key, value) that returns a new ConfigManager with the updated valueget_value(key, default=None) that retrieves a value with type inference{"host": "localhost", "port": 8080}, calling get_value("host") returns "localhost" and get_value("port") returns 8080 @testupdate_config("port", 9000) is called on a ConfigManager, it returns a new ConfigManager instance with the updated port value, and the original ConfigManager remains unchanged @testget_value("missing_key", "default_value") is called for a non-existent key, it returns "default_value" @test@generates
from typing import TypeVar, Generic, Optional, Any
K = TypeVar('K')
V = TypeVar('V')
class ConfigManager(Generic[K, V]):
"""
A type-safe configuration manager using immutable dictionaries.
This class provides a type-safe interface for managing configuration
data with proper static type checking support.
"""
def __init__(self, initial_config: dict[K, V]) -> None:
"""
Initialize the ConfigManager with an initial configuration.
Args:
initial_config: Dictionary containing the initial configuration
"""
...
def get_config(self) -> Any:
"""
Get the current configuration as an immutable dictionary.
Returns:
The current configuration
"""
...
def update_config(self, key: K, value: V) -> 'ConfigManager[K, V]':
"""
Create a new ConfigManager with an updated key-value pair.
Args:
key: The configuration key to update
value: The new value for the key
Returns:
A new ConfigManager instance with the updated configuration
"""
...
def get_value(self, key: K, default: Optional[V] = None) -> Optional[V]:
"""
Retrieve a configuration value by key with an optional default.
Args:
key: The configuration key to retrieve
default: The default value if the key is not found
Returns:
The value associated with the key, or the default if not found
"""
...Provides immutable dictionary implementation with type hints and mypy support.