{
  "id": "python/unittest-mock-autospec-call-arg",
  "signature": "TypeError: _mock_children() got an unexpected keyword argument 'autospec'\n  File \".../unittest/mock.py\", line ..., in __init__\n    self._mock_children = {}",
  "signature_zh": "TypeError: _mock_children() 收到意外的关键字参数 'autospec'\n  文件 \".../unittest/mock.py\"，行 ...，在 __init__ 中\n    self._mock_children = {}",
  "regex": "TypeError:\\ _mock_children\\(\\)\\ got\\ an\\ unexpected\\ keyword\\ argument\\ 'autospec'\\\n\\ \\ File\\ \"\\.\\.\\./unittest/mock\\.py\",\\ line\\ \\.\\.\\.,\\ in\\ __init__\\\n\\ \\ \\ \\ self\\._mock_children\\ =\\ \\{\\}",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A custom Mock subclass overrides __init__ without forwarding **kwargs to super().__init__, so attributes like autospec/spec_set are silently dropped or cause errors when combined with `create_autospec`.",
  "root_cause_type": "generic",
  "root_cause_zh": "自定义 Mock 子类覆盖了 __init__ 但未将 **kwargs 转发给 super().__init__，导致 autospec/spec_set 等属性被静默丢弃，或在配合 `create_autospec` 时引发错误。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Loses signature checking; tests pass with typos in method names, defeating the purpose.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The subclass __init__ swallows the kwarg, so autospec is not applied.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "from unittest.mock import Mock\n\nclass MyMock(Mock):\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "from unittest.mock import create_autospec\n\nmock_client = create_autospec(MyClient, instance=True)\nmock_client.fetch.return_value = {\"ok\": True}",
      "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.81,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-28",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}