# TypeError: 不支持的操作数类型: 'str' 和 'float'

- **ID:** `python/pytest-approx-comparison-error`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

使用 pytest.approx() 与非数字类型，例如比较字符串和浮点数，导致类型错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Ensure both operands are numeric: `assert pytest.approx(3.14) == float('3.14')`
   ```
2. **** (90% 成功率)
   ```
   Convert the string to float explicitly: `assert pytest.approx(float('3.14'), 0.01) == 3.14`
   ```

## 无效尝试

- **** — pytest.approx() requires numeric types; string comparison does not support approximate matching. (85% 失败率)
- **** — This duplicates functionality of approx() and may still fail if types are mismatched. (70% 失败率)
