{
  "id": "python/asyncio-await-in-non-async",
  "signature": "SyntaxError: 'await' outside async function",
  "signature_zh": "语法错误：'await' 在异步函数外部",
  "regex": "SyntaxError:\\ 'await'\\ outside\\ async\\ function",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Using the await keyword inside a synchronous function or at module level without an enclosing async def, violating Python syntax rules.",
  "root_cause_type": "generic",
  "root_cause_zh": "在同步函数内或模块级别使用 await 关键字，而没有包含它的 async def，违反了 Python 语法规则。",
  "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": "Decorating the function with @asyncio.coroutine",
      "why_fails": "The @asyncio.coroutine decorator is deprecated and does not make a function async; await still requires async def.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using yield from instead of await",
      "why_fails": "yield from works with generators, not async functions; it will raise a different error.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Define the function with async def",
      "success_rate": 1.0,
      "how": "async def fetch_data(): return await some_async_func()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use asyncio.run() at module level with a wrapper",
      "success_rate": 0.95,
      "how": "async def main(): await fetch_data()\nif __name__ == '__main__': asyncio.run(main())",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}