Educational collection of surprising Python code snippets that demonstrate counter-intuitive behaviors and language internals
Overall
score
93%
A utility that manages a registry of callback functions with associated metadata, demonstrating proper handling of mutable default arguments and object references.
Register callback functions with optional metadata tags.
["api", "v1"] stores those tags with the function @testAccess metadata associated with registered functions.
{"tags": [], "config": {}} @test["api", "v1"] returns those tags in the metadata @test{"timeout": 30} returns that config in the metadata @testExecute registered functions and return their results.
@generates
class FunctionRegistry:
"""Manages a registry of callback functions with metadata."""
def register(self, name: str, func: callable, tags: list = None, config: dict = None) -> None:
"""
Register a callback function with optional tags and config.
Args:
name: Unique identifier for the function
func: The callable to register
tags: Optional list of string tags (creates new empty list if None)
config: Optional configuration dict (creates new empty dict if None)
"""
pass
def get_metadata(self, name: str) -> dict:
"""
Get the metadata for a registered function.
Returns:
dict: Dictionary with 'tags' (list) and 'config' (dict) keys
"""
pass
def execute(self, name: str, *args, **kwargs):
"""Execute a registered function with the given arguments."""
passEducational resource demonstrating Python's mutable default argument behavior and reference semantics.
Install with Tessl CLI
npx tessl i tessl/pypi-wtfpythondocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10