python
data_error
ai_generated
true
packaging.version.InvalidVersion:无效版本:'1.0.0-beta.1+build_42!'
packaging.version.InvalidVersion: Invalid version: '1.0.0-beta.1+build_42!'
ID: python/packaging-version-invalid-pep440
80%修复率
86%置信度
0证据数
2024-08-25首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8+ | active | — | — | — |
根因分析
版本字符串不符合 PEP 440。像 '!' 这样的字符或格式错误的前发布分隔符('-beta' 而非 'b')会被 packaging.version.Version 拒绝。
English
A version string does not conform to PEP 440. Characters like '!' or malformed pre-release separators ('-beta' vs 'b') are rejected by packaging.version.Version.
解决方案
-
85% 成功率
from packaging.version import Version, InvalidVersion raw = '1.0.0-beta.1+build_42!'.rstrip('!') v = Version(raw.replace('-beta', 'b')) print(v) # 1.0.0b1+build.42 -
90% 成功率
# pyproject.toml [project] version = "1.0.0b1" # PEP 440 pre-release form # or use dynamic versioning from git tags via setuptools-scm
无效尝试
常见但无效的做法:
-
90% 失败
LegacyVersion was removed in packaging 22+; importing it raises ImportError. Even when available, comparisons are unreliable.
-
80% 失败
Produces a different version (e.g. '100beta1build42') that no longer reflects intent and may collide with real releases.