{"type": "session", "harness": "deepseek-harness", "id": "misc-0015", "name": "Python decorators"} {"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}} {"type": "message", "message": {"role": "user", "content": "How do decorators work in Python?"}} {"type": "message", "message": {"role": "assistant", "content": "```python\ndef my_decorator(func):\n def wrapper(*args, **kwargs):\n print(\"Before function call\")\n result = func(*args, **kwargs)\n print(\"After function call\")\n return result\n return wrapper\n\n@my_decorator\ndef say_hello(name):\n print(f\"Hello, {name}!\")\n\n# Same as: say_hello = my_decorator(say_hello)\n```\n\nWith arguments:\n```python\nfrom functools import wraps\n\ndef repeat(times):\n def decorator(func):\n @wraps(func)\n def wrapper(*args, **kwargs):\n for _ in range(times):\n result = func(*args, **kwargs)\n return result\n return wrapper\n return decorator\n\n@repeat(times=3)\ndef greet():\n print(\"Hi!\")\n```"}}