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

Variable Name Logger with Selective Filtering

Create a logging utility that captures and logs variable names when values are assigned, with the ability to selectively filter out calls from specific modules or functions.

Requirements

Build a logging system that:

  1. Variable Name Capture: When a value is assigned to a variable, the system should capture the variable's name automatically.

  2. Selective Filtering: The system should support filtering to ignore variable name retrieval from:

    • Specific modules (including their submodules)
    • Specific functions by name
  3. Logging Output: For each captured assignment, log a message in the format: "Variable '{name}' assigned".

  4. Multiple Ignore Patterns: Support ignoring multiple modules and functions simultaneously.

Implementation Details

Create the following components:

Logger Class

  • A Logger class that captures variable names when values are created through it
  • Should have a create() method that returns a value and logs the variable name it's assigned to
  • Should accept ignore patterns to filter out specific modules and functions

Helper Functions

  • Create wrapper functions in separate files to test the ignore functionality
  • At least one wrapper function should be in a separate module file
  • At least one wrapper function should be a regular function in the same file

Test Cases

  • When creating a value with no ignore patterns, the variable name is captured correctly. @test

  • When creating a value through a wrapper function with that function ignored, the variable name (not the wrapper) is captured. @test

  • When creating a value through a wrapper module with that module ignored, the variable name (not the wrapper) is captured. @test

  • When creating a value with multiple ignore patterns (both functions and modules), all specified patterns are filtered correctly. @test

Implementation

@generates

API

class Logger:
    """Logger that captures variable names with selective filtering."""

    def __init__(self, ignore_modules=None, ignore_functions=None):
        """
        Initialize logger with ignore patterns.

        Args:
            ignore_modules: List of module names to ignore (e.g., ['helpers', 'utils'])
            ignore_functions: List of function names to ignore (e.g., ['wrapper', 'decorator'])
        """
        pass

    def create(self, value):
        """
        Create a value and log the variable name it's assigned to.

        Args:
            value: The value to return

        Returns:
            The value passed in
        """
        pass

    def get_logs(self):
        """
        Get all logged messages.

        Returns:
            List of log messages in order they were created
        """
        pass

Dependencies { .dependencies }

varname { .dependency }

Provides variable name introspection capabilities with filtering support.