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%
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.
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:
ConfigParser class that accepts a configuration dictionary in its constructorget_nested(path) method that returns values from the configuration that can be unpacked into nested tuple patternsa, (b, c) = parser.get_nested('section')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
@generates
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
"""
passProvides variable name introspection capabilities for tracking assignments.