CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-frozendict

A simple immutable dictionary implementation with hashing support and performance optimizations

85

1.30x
Overview
Eval results
Files

task.mdevals/scenario-9/

Configuration Reader

Build a configuration file reader that loads and queries configuration data using an immutable dictionary structure.

Requirements

Create a ConfigReader class that:

  1. Loads configuration data from a dictionary into an immutable internal structure
  2. Retrieves configuration values safely with optional default values
  3. Lists all configuration keys in the order they were added
  4. Validates required keys by checking if specific keys exist in the configuration

The configuration reader should ensure that once loaded, the configuration data cannot be modified.

Implementation Details

Configuration Loading

The ConfigReader should accept a dictionary during initialization and store it in an immutable format.

Value Retrieval

Provide a method to get configuration values by key. If a key doesn't exist, return a default value (None if not specified).

Key Listing

Provide a method to return all configuration keys in the order they were added.

Key Validation

Provide a method that checks whether all keys from a given list exist in the configuration. Return True only if all keys are present.

Test Cases

  • Loading an empty configuration and retrieving a non-existent key with default value "default" returns "default" @test
  • Loading configuration {"app.name": "MyApp", "app.version": "1.0"} and getting "app.name" returns "MyApp" @test
  • Loading configuration {"debug": True} and listing all keys returns a sequence containing "debug" @test
  • Loading configuration {"key1": "val1", "key2": "val2"} and validating that keys ["key1", "key2"] exist returns True @test
  • Loading configuration {"key1": "val1"} and validating that keys ["key1", "key2"] exist returns False @test

@generates

API

class ConfigReader:
    """A configuration reader that stores configuration in an immutable format."""

    def __init__(self, config: dict):
        """Initialize with a configuration dictionary."""
        pass

    def get(self, key: str, default=None):
        """Retrieve a configuration value by key, returning default if not found."""
        pass

    def keys(self):
        """Return all configuration keys in order."""
        pass

    def has_keys(self, keys: list) -> bool:
        """Check if all specified keys exist in the configuration."""
        pass

Dependencies { .dependencies }

frozendict { .dependency }

Provides immutable dictionary support for storing configuration data.

Install with Tessl CLI

npx tessl i tessl/pypi-frozendict

tile.json