Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

parse_quantity raises decimal.Overflow instead of ValueError for some large quantities

已关闭 适合新手
#2,735 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

从报告所指的第85行 kubernetes/utils/quantity.py 开始,检查现有的 parse_quantity 错误处理。使用 parse_quantity("2.e388635141Ki") 重现溢出,然后检查 quantity 解析测试中对格式错误输入的测试。当此输入始终引发 ValueError 且相关测试通过时,即为完成。

由索引模型根据 Issue 内容生成。

描述

What happened (please include outputs or screenshots):

While testing an experimental version of Perch, we found the following and figured it was worth a report.

parse_quantity raises ValueError for malformed quantities, but a quantity whose exponent overflows the decimal context escapes as decimal.Overflow:

from kubernetes.utils.quantity import parse_quantity

parse_quantity("abc")
# ValueError: Invalid number format: abc

parse_quantity("2.e388635141Ki")
# decimal.Overflow: [<class 'decimal.Overflow'>]

What you expected to happen:

A ValueError, like other quantities it can't handle, so callers that catch ValueError around it keep working.

How to reproduce it (as minimally and precisely as possible):

Run the snippet above against master. No cluster is needed.

Anything else we need to know?:

It's raised at kubernetes/utils/quantity.py:85, return number * (base ** exponent). The API server won't produce a quantity this large, so in practice it shows up with hand-written or third-party manifests. Catching decimal.DecimalException there and raising ValueError would keep the error type consistent.

Environment:

  • Kubernetes version (kubectl version): not needed, no cluster involved
  • OS (e.g., MacOS 10.13.6): macOS 26.2 (arm64)
  • Python version (python --version): 3.14.2
  • Python client version (pip list | grep kubernetes): 37.0.0+snapshot (master, bb9199f7)
主要语言
Python
星标
7.7k
派生
3.5k
平均合并
1 天 13 小时
30 天内合并 PR
19

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

kubernetes-client/python 的其他 Issue

查看 kubernetes-client/python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。