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

Configuration Dictionary Builder

Build a utility that creates configuration dictionaries from variable names and their values, useful for logging and debugging scenarios.

Specification

Create a Python module that provides a function to build configuration dictionaries. The function should accept multiple variables as arguments and return a dictionary where the keys are the string names of those variables.

Requirements

  1. Implement a function build_config that:

    • Accepts any number of positional arguments (variables)
    • Returns a dictionary where keys are the variable names (as strings) and values are the variable values
    • When a single variable is passed, it should still return a dictionary with one entry
  2. Implement a function build_config_with_prefix that:

    • Accepts any number of positional arguments (variables)
    • Accepts a keyword argument prefix (string) that defaults to "cfg"
    • Returns a dictionary where keys are prefixed with the prefix value followed by an underscore
    • Example: with prefix "app", a variable timeout becomes key "app_timeout"
  3. Implement a function get_full_path that:

    • Accepts a single argument (which may be a nested attribute like obj.attr.subattr)
    • Returns the full attribute path as a string
    • Example: if called with server.config.port, returns "server.config.port"

Implementation

@generates

API

def build_config(*args) -> dict:
    """
    Build a configuration dictionary from variables.

    Args:
        *args: Variables to include in the configuration

    Returns:
        Dictionary with variable names as keys and their values
    """
    pass

def build_config_with_prefix(*args, prefix: str = "cfg") -> dict:
    """
    Build a configuration dictionary with prefixed keys.

    Args:
        *args: Variables to include in the configuration
        prefix: String prefix for all keys (default: "cfg")

    Returns:
        Dictionary with prefixed variable names as keys and their values
    """
    pass

def get_full_path(arg) -> str:
    """
    Get the full attribute path of a variable or attribute chain.

    Args:
        arg: A variable or attribute chain

    Returns:
        The full path as a string
    """
    pass

Test Cases

  • Given variables x=10 and y=20, build_config(x, y) returns {"x": 10, "y": 20} @test
  • Given variable name="test", build_config(name) returns {"name": "test"} @test
  • Given variables host="localhost" and port=8080 with prefix "server", build_config_with_prefix(host, port, prefix="server") returns {"server_host": "localhost", "server_port": 8080} @test
  • Given an object server with nested attribute server.config.port = 3000, get_full_path(server.config.port) returns "server.config.port" @test

Dependencies { .dependencies }

varname { .dependency }

Provides functionality for retrieving variable names at runtime.

@satisfied-by