or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/wtfpython@3.0.x
tile.json

tessl/pypi-wtfpython

tessl install tessl/pypi-wtfpython@3.0.0

Educational 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%

task.mdevals/scenario-4/

Method Call Tracker

A utility that tracks method calls on objects by wrapping methods to record their invocations without modifying the original class definition.

Capabilities

Method Call Recording

  • When a tracked method is called with obj.method(1, 2, key='value'), it records {'args': (1, 2), 'kwargs': {'key': 'value'}} in obj.calls @test
  • A tracked method returns the same value as the original unwrapped method @test
  • A tracked method can access instance attributes via self just like the original method @test

Multiple Instance Support

  • When two instances of the same class each have a tracked method, calls are recorded separately in each instance's calls list @test

Implementation

@generates

API

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.
    """
    pass

Dependencies { .dependencies }

This implementation uses only Python standard library features and requires no external dependencies.