{
  "id": "python/asyncio-timeout-context-manager-not-async",
  "signature": "TypeError: 'async with' received an object from __aenter__ that does not implement __await__: Timeout",
  "signature_zh": "TypeError: 'async with' 从 __aenter__ 收到的对象未实现 __await__：Timeout",
  "regex": "TypeError:\\ 'async\\ with'\\ received\\ an\\ object\\ from\\ __aenter__\\ that\\ does\\ not\\ implement\\ __await__:\\ Timeout",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Code uses async with asyncio.timeout() on a Python version where asyncio.timeout exists only as a plain context manager (or on an older version where it does not exist at all), or a custom Timeout object is returned instead of a coroutine.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 asyncio.timeout 仅作为普通上下文管理器存在的 Python 版本上使用 async with asyncio.timeout()（或在根本不支持它的旧版本上），或返回了自定义 Timeout 对象而非协程。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "asyncio.timeout is not a coroutine; awaiting it raises TypeError.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Does not actually cancel the inner coroutine, so the timeout never triggers.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "try:\n    result = await asyncio.wait_for(coro(), timeout=5.0)\nexcept asyncio.TimeoutError:\n    result = None",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "async with asyncio.timeout(5.0):\n    await coro()\n# note: 'async with', but NOT 'async with await'",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}