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

Configuration Value Selector

Build a configuration value selector that retrieves specific configuration items by their position in insertion order. The selector should support both forward and backward positional access.

Requirements

Your implementation should provide a ConfigSelector class with the following behavior:

  1. Initialize with configuration data (key-value pairs) that maintains insertion order
  2. Support retrieving keys by position (0-indexed from the start)
  3. Support retrieving values by position (0-indexed from the start)
  4. Support retrieving key-value pairs by position (0-indexed from the start)
  5. Support negative indexing to access items from the end (e.g., -1 for last item)
  6. Raise appropriate errors for out-of-range indices
  7. The configuration data should remain immutable after initialization

Implementation

@generates

API

class ConfigSelector:
    """
    A configuration selector that allows positional access to configuration items.

    Configuration data is stored in insertion order and remains immutable after initialization.
    """

    def __init__(self, config_data):
        """
        Initialize the selector with configuration data.

        Args:
            config_data: A dictionary containing configuration key-value pairs
        """
        pass

    def get_key_at(self, index):
        """
        Get the configuration key at the specified position.

        Args:
            index: Integer position (supports negative indexing)

        Returns:
            The key at the specified position

        Raises:
            IndexError: If index is out of range
        """
        pass

    def get_value_at(self, index):
        """
        Get the configuration value at the specified position.

        Args:
            index: Integer position (supports negative indexing)

        Returns:
            The value at the specified position

        Raises:
            IndexError: If index is out of range
        """
        pass

    def get_item_at(self, index):
        """
        Get the configuration key-value pair at the specified position.

        Args:
            index: Integer position (supports negative indexing)

        Returns:
            A tuple of (key, value) at the specified position

        Raises:
            IndexError: If index is out of range
        """
        pass

Test Cases

  • Given a selector initialized with {"host": "localhost", "port": 8080, "debug": True}, calling get_key_at(0) returns "host" @test
  • Given a selector initialized with {"host": "localhost", "port": 8080, "debug": True}, calling get_value_at(1) returns 8080 @test
  • Given a selector initialized with {"host": "localhost", "port": 8080, "debug": True}, calling get_item_at(2) returns ("debug", True) @test
  • Given a selector initialized with {"host": "localhost", "port": 8080, "debug": True}, calling get_key_at(-1) returns "debug" @test
  • Given a selector initialized with {"host": "localhost", "port": 8080, "debug": True}, calling get_value_at(-2) returns 8080 @test
  • Given a selector initialized with {"host": "localhost", "port": 8080}, calling get_key_at(5) raises IndexError @test
  • Given a selector initialized with {"host": "localhost", "port": 8080}, calling get_item_at(-10) raises IndexError @test

Dependencies { .dependencies }

frozendict { .dependency }

Provides immutable dictionary support with positional access capabilities.

@satisfied-by