Educational collection of surprising Python code snippets that demonstrate counter-intuitive behaviors and language internals
Overall
score
93%
{
"context": "This criteria evaluates how well the engineer demonstrates understanding of Python's exception handling internals, specifically the automatic deletion of exception variables after except blocks and the finally block's ability to override return statements in try/except blocks.",
"type": "weighted_checklist",
"checklist": [
{
"name": "Exception variable capture",
"description": "Uses 'except ExceptionType as var:' syntax to capture an exception into a variable within an except block",
"max_score": 15
},
{
"name": "Variable deletion detection",
"description": "Attempts to access the exception variable outside the except block (after the except block ends) and properly handles the error that results from Python's automatic deletion",
"max_score": 25
},
{
"name": "Error handling structure",
"description": "Uses a try-except block to catch and handle the error raised when attempting to access the deleted exception variable, allowing the function to return information about the error type",
"max_score": 15
},
{
"name": "Try-finally-return structure",
"description": "Implements try-finally blocks with return statements in both the try block and the finally block",
"max_score": 15
},
{
"name": "Except-finally-return structure",
"description": "Implements try-except-finally blocks with return statements in both the except block and the finally block",
"max_score": 15
},
{
"name": "Finally override behavior",
"description": "Demonstrates that return statements in finally blocks always override return statements in try or except blocks (the finally return value is what the function ultimately returns)",
"max_score": 15
}
]
}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