or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/varname@0.15.x
tile.json

tessl/pypi-varname

tessl install tessl/pypi-varname@0.15.0

Dark magics about variable names in python

Agent Success

Agent success rate when using this tile

90%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.41x

Baseline

Agent success rate without this tile

64%

task.mdevals/scenario-9/

Configuration Parser

Build a configuration parser that reads structured configuration data and unpacks it into variables, automatically tracking which variable names are assigned to which configuration values.

Problem

Create a system that parses nested configuration data structures and assigns them to variables while tracking the assignment names. The system should support multi-level nested structures where configuration values can be unpacked into variables at different nesting levels.

Your task is to implement a ConfigParser class that:

  1. Takes a configuration dictionary with nested structures
  2. Provides a method to retrieve nested values that tracks the variable names they're assigned to
  3. Returns a tuple of values that can be unpacked into nested patterns
  4. Maintains a mapping of which variable names were assigned to which configuration paths

Requirements

  • Implement a ConfigParser class that accepts a configuration dictionary in its constructor
  • Implement a get_nested(path) method that returns values from the configuration that can be unpacked into nested tuple patterns
  • Track variable names when values are unpacked into nested patterns like a, (b, c) = parser.get_nested('section')
  • Store the mapping of variable names to configuration paths in an accessible attribute
  • Handle cases where the configuration has 2-3 levels of nesting

Test Cases

  • Given a configuration with nested structure {'server': {'host': 'localhost', 'port': 8080}}, when unpacking with host, port = parser.get_nested('server'), the parser tracks that 'host' was assigned 'localhost' and 'port' was assigned 8080. @test

  • Given a configuration with multi-level nesting {'database': {'primary': {'host': 'db1.com', 'credentials': {'user': 'admin', 'password': 'secret'}}}}, when unpacking with host, (user, password) = parser.get_nested('database.primary'), the parser correctly tracks all three variable names. @test

  • Given a configuration with three-level structure, when unpacking with pattern a, (b, (c, d)) = parser.get_nested('section'), the parser tracks all four variable names at their respective nesting levels. @test

Implementation

@generates

API

class ConfigParser:
    """
    A configuration parser that tracks variable names during nested tuple unpacking.
    """

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

        Args:
            config: A dictionary containing configuration data with potential nesting
        """
        pass

    def get_nested(self, path: str) -> tuple:
        """
        Retrieve nested configuration values for unpacking.

        Returns a tuple that can be unpacked into nested patterns. Tracks the
        variable names used during unpacking.

        Args:
            path: A dot-separated path to the configuration section (e.g., 'database.primary')

        Returns:
            A tuple of values that can be unpacked into nested variable patterns
        """
        pass

    @property
    def variable_mapping(self) -> dict:
        """
        Get the mapping of variable names to configuration values.

        Returns:
            Dictionary mapping variable names to their assigned configuration values
        """
        pass

Dependencies { .dependencies }

varname { .dependency }

Provides variable name introspection capabilities for tracking assignments.