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 Python utility that demonstrates variable scope behavior and closure handling.
@generates
def create_closure_functions(n: int) -> list:
"""
Creates a list of n functions where each function returns its index.
Must properly handle closure variable capture.
Args:
n: Number of functions to create
Returns:
List of functions, where the i-th function returns i
"""
pass
def create_lambda_closures(values: list) -> list:
"""
Creates a list of lambda functions that capture values from the input list.
Args:
values: List of values to capture
Returns:
List of lambda functions, where the i-th lambda returns values[i]
"""
pass
def modify_with_nonlocal(initial: int, increment: int) -> int:
"""
Uses an inner function to modify an enclosing scope variable.
Args:
initial: Initial value of the enclosing variable
increment: Amount to increment by
Returns:
The modified value after incrementing
"""
pass
def set_global_counter(value: int) -> None:
"""
Sets the module-level variable 'counter' to the given value.
Args:
value: Value to set for the global counter
"""
pass
def trigger_unbound_local_error() -> None:
"""
Demonstrates UnboundLocalError by reading before assignment.
Raises:
UnboundLocalError: Always raised when called
"""
passUses built-in Python features for scope and closure demonstration. No external dependencies required.