tessl install tessl/pypi-varname@0.15.0Dark 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%
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.
Build a logging system that:
Variable Name Capture: When a value is assigned to a variable, the system should capture the variable's name automatically.
Selective Filtering: The system should support filtering to ignore variable name retrieval from:
Logging Output: For each captured assignment, log a message in the format: "Variable '{name}' assigned".
Multiple Ignore Patterns: Support ignoring multiple modules and functions simultaneously.
Create the following components:
Logger class that captures variable names when values are created through itcreate() method that returns a value and logs the variable name it's assigned toWhen 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
@generates
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
"""
passProvides variable name introspection capabilities with filtering support.