# TypeError: 'Timeout' 对象不可等待

- **ID:** `python/asyncio-timeout-context-manager-required`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在 Python 3.11+ 中，asyncio.timeout() 返回异步上下文管理器，而不是可等待对象。为 asyncio.wait_for 或旧模式编写的代码错误地 await 了它。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   async with asyncio.timeout(5):
    data = await fetch()
   ```
2. **** (88% 成功率)
   ```
   try:
    async with asyncio.timeout(5):
        return await fetch()
except AttributeError:
    return await asyncio.wait_for(fetch(), timeout=5)
   ```
3. **** (90% 成功率)
   ```
   import time
loop = asyncio.get_running_loop()
deadline = loop.time() + 5
async with asyncio.timeout_at(deadline):
    await fetch()
   ```

## 无效尝试

- **** — Timeout is not callable; raises TypeError: 'Timeout' object is not callable. (90% 失败率)
- **** — wait_for expects an awaitable; Timeout is a context manager, not awaitable. (85% 失败率)
