CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-varname

Dark magics about variable names in python

Overall
score

90%

Overview
Eval results
Files

task.mdevals/scenario-4/

Self-Documenting Configuration System

Build a configuration system that automatically tracks variable assignments and method chaining patterns using Python properties.

Requirements

Create a ConfigBuilder class that:

  1. Has a property that returns the builder itself and captures the name of the variable it's assigned to
  2. Has a property that enables method chaining and detects which method will be called next
  3. Stores captured variable names and method chain information for later inspection

Specifications

Variable Name Tracking

The ConfigBuilder class should have a get_config() property that:

  • Returns the builder instance itself
  • Captures and stores the variable name it's assigned to
  • Can be accessed multiple times with different variable assignments

Method Chain Detection

The ConfigBuilder class should have a chain() property that:

  • Returns the builder instance to enable method chaining
  • Detects which method will be called immediately after
  • Stores the detected method name internally

Data Access

The class should provide methods to retrieve captured information:

  • get_variable_names() - returns a list of all captured variable names
  • get_next_methods() - returns a list of all detected next method calls

Test Cases

  • When assigning config = builder.get_config(), the builder stores "config" as a captured variable name @test
  • When calling builder.chain().save(), the builder detects and stores "save" as the next method @test
  • Multiple variable assignments are tracked: config1 = builder.get_config() followed by config2 = builder.get_config() stores both "config1" and "config2" @test
  • The class includes stub methods save(), load(), and validate() that return the builder to support chaining @test

@generates

API

class ConfigBuilder:
    """Configuration builder with self-documenting capabilities."""

    def __init__(self):
        """Initialize the builder with empty tracking lists."""
        pass

    @property
    def get_config(self):
        """Property that captures the variable name it's assigned to and returns self."""
        pass

    @property
    def chain(self):
        """Property that detects the next method call and returns self."""
        pass

    def get_variable_names(self) -> list[str]:
        """Return list of all captured variable names."""
        pass

    def get_next_methods(self) -> list[str]:
        """Return list of all detected next method calls."""
        pass

    def save(self):
        """Stub method for chaining support. Returns self."""
        pass

    def load(self):
        """Stub method for chaining support. Returns self."""
        pass

    def validate(self):
        """Stub method for chaining support. Returns self."""
        pass

Dependencies { .dependencies }

varname { .dependency }

Provides metaprogramming capabilities for variable name retrieval and method chain detection.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/pypi-varname

tile.json