{
  "id": "python/asyncio-sync-primitive-type-error",
  "signature": "TypeError: a coroutine was expected, got <class 'str'>",
  "signature_zh": "类型错误：期望一个协程，但得到 <class 'str'>",
  "regex": "TypeError:\\ a\\ coroutine\\ was\\ expected,\\ got\\ <class\\ 'str'>",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A non-coroutine object (e.g., a string) is passed to asyncio functions like asyncio.wait() or asyncio.gather() that expect coroutines.",
  "root_cause_type": "generic",
  "root_cause_zh": "将非协程对象（例如字符串）传递给期望协程的 asyncio 函数，如 asyncio.wait() 或 asyncio.gather()。",
  "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Wrapping the object in a list",
      "why_fails": "The function still expects coroutines, not a list of strings.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using asyncio.ensure_future() on the object",
      "why_fails": "ensure_future() expects a coroutine or future, not a string.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure the function is defined as async and called correctly",
      "success_rate": 0.95,
      "how": "async def my_coro():\n    return 'result'\nawait asyncio.gather(my_coro())",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use asyncio.iscoroutine() to check before passing",
      "success_rate": 0.9,
      "how": "if asyncio.iscoroutine(obj):\n    await asyncio.gather(obj)\nelse:\n    # handle non-coroutine",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-10-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}