Dark magics about variable names in python
Overall
score
90%
Build a task manager that tracks and stores async operation results using the variable names they're assigned to as identifiers.
Create a system that:
The system should work seamlessly with Python's async/await syntax, automatically capturing variable names from async function calls.
@generates
class TaskResult:
"""Represents the result of an async task with automatic variable name capture."""
def __init__(self, value):
"""
Initialize a task result that captures its variable name.
Args:
value: The value to store
"""
pass
@property
def identifier(self):
"""Get the identifier (variable name) for this result."""
pass
@property
def value(self):
"""Get the stored value."""
pass
async def create_task_result(value):
"""
Create a task result asynchronously.
Args:
value: The value to wrap in a TaskResult
Returns:
TaskResult: A result object with automatic variable name capture
"""
pass
class TaskRegistry:
"""Registry for storing and retrieving task results by identifier."""
def __init__(self):
"""Initialize an empty task registry."""
pass
def register(self, task_result):
"""
Register a task result in the registry.
Args:
task_result: A TaskResult instance to register
"""
pass
def get(self, identifier):
"""
Retrieve a task result by its identifier.
Args:
identifier: The identifier (variable name) to look up
Returns:
The value stored under that identifier, or None if not found
"""
pass
def list_all(self):
"""
List all registered results.
Returns:
dict: A dictionary mapping identifiers to their values
"""
passProvides variable name introspection support for capturing variable names at runtime.
Install with Tessl CLI
npx tessl i tessl/pypi-varnameevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10