Python PEP 是作为 proposed/amended 实施的还是有回旋余地?

Are Python PEPs implemented as proposed/amended or is there wiggle room?

我刚刚在 PEP 3127 中注意到(它合理化了文字和 int() 参数的基数计算,因此,例如,010 不再是有效的文字,必须改为 0o10 如果需要八进制),PEP 的一个特定部分没有实现。

我具体参考下面引用的部分:

Tokenizer exception handling

If an invalid token contains a leading "0", the exception error message should be more informative than the current "SyntaxError: invalid token". It should explain that decimal numbers may not have a leading zero, and that octal numbers require an "o" after the leading zero.

但是,当我尝试使用这种(现在无效的)格式时,我仍然看到旧的(信息量较少的)错误,根据以下记录:

MyPromptHere> python3
Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 010
  File "<stdin>", line 1
    x = 010
          ^
SyntaxError: invalid token

>>> int('010', 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 0: '010'

>>> _

现在我真的不关心这是一个奇怪的错误,因为我的大部分报酬来自神秘的错误:-)但是,据我了解, PEP 甚至 获得赞助后也会经历修订过程,所以我很好奇为什么:

或者这仅仅是“应该”一词的用法比正常标准的“必需”术语(如“应”或“必须”)更弱吗?我不确定,因为根据上面的文字记录,在处理 int():

的部分似乎遵守了“应该”

int() exception handling

The ValueError raised for any call to int() with a string should at least explicitly contain the base in the error message, e.g.: ValueError: invalid literal for base 8 int(): 09.

这对您来说可能是 python 版本差异。

Python 3.8.1 (default, Jan 13 2020, 22:28:48) 
>>> 010
  File "<stdin>", line 1
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers

此外,在 PEP 3127 的 "Open Issues" 部分,它指出

There are still some strong feelings that '0123' should be allowed as a literal decimal in Python 3.0. If this is the right thing to do, this can easily be covered in an additional PEP. This proposal only takes the first step of making '0123' not be a valid octal number, for reasons covered in the rationale.

对我来说,这意味着更改错误消息没有硬性要求。这是一个提供更多信息的建议,最终在某个时候实施(参见上面的 3.8.1 输出)。