{
  "id": "python/assertionerror-assert-in-dict",
  "signature": "AssertionError: assert 'key' in {'a': 1}",
  "signature_zh": "断言错误：断言 'key' 在 {'a': 1} 中",
  "regex": "AssertionError:\\ assert\\ 'key'\\ in\\ \\{'a':\\ 1\\}",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The key is not present in the dictionary, causing the 'in' operator to return False.",
  "root_cause_type": "generic",
  "root_cause_zh": "键不在字典中，导致 'in' 运算符返回 False。",
  "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Checking with .get() and ignoring None",
      "why_fails": ".get() returns None for missing keys, which may mask the absence.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using assertEqual with dict.keys()",
      "why_fails": "dict.keys() returns a view; comparison may be misleading.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add the key to the dictionary before assertion",
      "success_rate": 0.95,
      "how": "d = {'a': 1}; d['key'] = 'value'; assert 'key' in d",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use assertIn for better error messages",
      "success_rate": 0.9,
      "how": "self.assertIn('key', {'a': 1})",
      "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-08-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}