Educational collection of surprising Python code snippets that demonstrate counter-intuitive behaviors and language internals
93
Pending
Does it follow best practices?
Impact
93%
1.05xAverage score across 10 eval scenarios
Pending
The risk profile of this skill
{
"context": "This criteria evaluates how well the engineer uses Python's inspect module and demonstrates understanding of closure semantics, late binding, early binding, and generator scoping. The focus is on correct usage of inspect.getclosurevars() and proper implementation of closure variable capture patterns.",
"type": "weighted_checklist",
"checklist": [
{
"name": "Uses inspect.getclosurevars",
"description": "The inspect_closure function correctly uses inspect.getclosurevars() to examine the closure and extract captured variables from the nonlocals, globals, builtins, and unbound attributes.",
"max_score": 25
},
{
"name": "Late binding implementation",
"description": "The create_late_binding_closures function correctly demonstrates late binding by creating closures that capture loop variables by reference, resulting in all closures sharing the same final value of the loop variable.",
"max_score": 20
},
{
"name": "Early binding pattern",
"description": "The create_early_binding_closures function correctly implements early binding using either default parameter values (e.g., lambda i=i: i) or similar techniques to capture the loop variable's value at creation time.",
"max_score": 20
},
{
"name": "Generator scope analysis",
"description": "The analyze_generator_scope function correctly uses inspect.getclosurevars() or similar inspect module functions to analyze the generator function's closure variables before the generator is instantiated.",
"max_score": 20
},
{
"name": "Closure validation",
"description": "The inspect_closure function properly validates that the input is a closure by checking if func.__closure__ is not None and handles non-closure functions appropriately.",
"max_score": 10
},
{
"name": "Generator validation",
"description": "The analyze_generator_scope function properly validates that the input is a generator function using inspect.isgeneratorfunction() or by checking for appropriate attributes.",
"max_score": 5
}
]
}docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10