tessl install tessl/pypi-wtfpython@3.0.0Educational collection of surprising Python code snippets that demonstrate counter-intuitive behaviors and language internals
Agent Success
Agent success rate when using this tile
93%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.06x
Baseline
Agent success rate without this tile
88%
A utility that tracks method calls on objects by wrapping methods to record their invocations without modifying the original class definition.
obj.method(1, 2, key='value'), it records {'args': (1, 2), 'kwargs': {'key': 'value'}} in obj.calls @testself just like the original method @testcalls list @test@generates
class TrackedMethod:
"""
A descriptor that wraps a method to track its calls while preserving method behavior.
Should track calls in a list accessible via the 'calls' attribute on the instance.
Each call record should be a dictionary with 'args' and 'kwargs' keys.
"""
def __init__(self, method):
"""Initialize with the method to track."""
pass
def __get__(self, instance, owner):
"""Implement descriptor protocol to return bound callable."""
pass
def track_method(obj, method_name):
"""
Replace a method on an object instance with a tracked version.
Args:
obj: The object instance to modify
method_name: Name of the method to track
Creates a 'calls' attribute on the instance (list of dicts) if not present.
"""
passThis implementation uses only Python standard library features and requires no external dependencies.