{
  "id": "python/pytest-approx-comparison-error",
  "signature": "TypeError: unsupported operand type(s) for -: 'str' and 'float'",
  "signature_zh": "TypeError: 不支持的操作数类型: 'str' 和 'float'",
  "regex": "TypeError:\\ unsupported\\ operand\\ type\\(s\\)\\ for\\ \\-:\\ 'str'\\ and\\ 'float'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Using pytest.approx() with non-numeric types, such as comparing a string to a float, causing a type error.",
  "root_cause_type": "generic",
  "root_cause_zh": "使用 pytest.approx() 与非数字类型，例如比较字符串和浮点数，导致类型错误。",
  "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": "",
      "why_fails": "pytest.approx() requires numeric types; string comparison does not support approximate matching.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This duplicates functionality of approx() and may still fail if types are mismatched.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Ensure both operands are numeric: `assert pytest.approx(3.14) == float('3.14')`",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Convert the string to float explicitly: `assert pytest.approx(float('3.14'), 0.01) == 3.14`",
      "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": "2025-05-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}