{
  "id": "python/unittest-mock-side-effect-raises",
  "signature": "TypeError: 'Exception' object is not callable",
  "signature_zh": "类型错误：'Exception' 对象不可调用",
  "regex": "TypeError:\\ 'Exception'\\ object\\ is\\ not\\ callable",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "在 mock 的 side_effect 中传入异常实例而不是异常类，导致调用时抛出 TypeError。",
  "root_cause_type": "generic",
  "root_cause_zh": "在 mock 的 side_effect 中传入异常实例而不是异常类，导致调用时抛出 TypeError。",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "side_effect=ValueError('msg')",
      "why_fails": "尝试将 side_effect 设置为异常实例，但应该用类",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "side_effect=lambda: raise ValueError",
      "why_fails": "尝试在 side_effect 中调用 raise 语句，但语法错误",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "使用异常类",
      "success_rate": 0.95,
      "how": "mock.side_effect = ValueError\nmock()  # 抛出 ValueError",
      "condition": "",
      "sources": []
    },
    {
      "action": "使用 lambda 抛出异常",
      "success_rate": 0.8,
      "how": "mock.side_effect = lambda: (_ for _ in ()).throw(ValueError('msg'))",
      "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": "2025-05-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}