{
  "id": "python/pytest-assertion-repr-recursion",
  "signature": "RecursionError: maximum recursion depth exceeded while calling a Python object\n(during assertion introspection of a self-referential object)",
  "signature_zh": "RecursionError：调用 Python 对象时超出最大递归深度\n（在对自引用对象进行断言内省期间）",
  "regex": "RecursionError:\\ maximum\\ recursion\\ depth\\ exceeded\\ while\\ calling\\ a\\ Python\\ object\\\n\\(during\\ assertion\\ introspection\\ of\\ a\\ self\\-referential\\ object\\)",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "An object compared in an assert has a __repr__ that recurses infinitely (e.g., a tree node whose children include itself), and pytest's assertion rewriting calls repr for the diff.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 assert 中比较的对象具有无限递归的 __repr__（例如子节点包含自身的树节点），而 pytest 的断言重写调用 repr 生成差异。",
  "versions": [
    {
      "version": "7.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "May segfault the interpreter and doesn't fix the cyclic repr.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Silently passes tests; hides real failures.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Loses all diff quality; the repr still recurses when printed.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "class Node:\n    def __repr__(self):\n        return f\"Node(id={id(self)}, value={self.value!r})\"",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "assert node.value == expected.value\nassert node.parent_id == expected.parent_id",
      "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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-10-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}