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

Type-Safe Configuration Manager

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.

Requirements

Implement a configuration manager with the following features:

  1. Configuration Storage: Store configuration data in an immutable structure that supports type checking
  2. Type-Safe Updates: Create new configurations with updated values while maintaining type safety
  3. Static Type Checking: All operations must pass mypy static type checking without errors

Implementation Details

Create a config_manager.py file that includes:

  • A ConfigManager class that wraps an immutable dictionary
  • A method get_config() that returns the current configuration with proper generic typing
  • A method update_config(key, value) that returns a new ConfigManager with the updated value
  • A method get_value(key, default=None) that retrieves a value with type inference
  • Type hints for all methods and functions
  • The implementation must use an immutable dictionary type for internal storage

Test Cases

  • When a ConfigManager is created with {"host": "localhost", "port": 8080}, calling get_value("host") returns "localhost" and get_value("port") returns 8080 @test
  • When update_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 @test
  • When get_value("missing_key", "default_value") is called for a non-existent key, it returns "default_value" @test
  • When the module is type-checked with mypy, it produces no type errors @test

Implementation

@generates

API

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
        """
        ...

Dependencies { .dependencies }

frozendict { .dependency }

Provides immutable dictionary implementation with type hints and mypy support.