试图向朋友解释语义版本控制的重要性时,我遇到了以下困境。
假设我们有 library libfoo
, version1.2.3
公开了以下功能:
def foo(x, y):
"""
Compute the sum of the operands.
:param x: The first argument.
:param y: The second argument.
:returns: The sum of `x` and `y`.
"""
return x + y
现在假设此函数及其文档更改为:
def foo(a, b):
"""
Compute the sum of the operands.
:param a: The first argument.
:param b: The second argument.
:returns: The sum of `a` and `b`.
"""
return a + b
我的第一印象是说下一个版本将是1.2.4
,因为公共界面没有改变。例如,像这样调用函数的人根本不会注意到变化:
foo(3, 4)
但再想一想,这很可能是一个API 中断,因为 Python 允许通过参数名称来指定参数。如果有人像这样调用我的函数:
foo(y=4, x=3)
这将不再适用于 version 1.2.4
,从而破坏了语义版本控制合同。
另一方面,这样的变化似乎很小,以至于我对将版本增加到2.0.0
.
总而言之,这是否构成 API 中断?在这种情况下,下一个版本号应该是什么?