为什么某些内置函数的语法错误消息不同?

Why syntax error messages for some built-in functions are different?

我最近发现了一些奇怪的事情。我输入了类似

的内容
exec code

而且我显然出错了。有趣的是错误描述 - SyntaxError: Missing parentheses in call to 'exec'。我还没有找到任何其他可以提供类似详细信息的功能。例如,如果我有

eval code

我得到 SyntaxError: invalid syntax。我发现的所有用户定义函数和所有内置函数,e。 G。 min, filter, 行为相同。

为什么这些错误消息不一致?

由于 exec code 在 Python 2 中是有效语法,但在 Python 3 中不是,此错误消息比一般 SyntaxError 更详细,因为它是 (并且)当一个人从 Python 2 过渡到 Python 3.

时非常流行(嗯,和 exec 的用法一样流行)

在 Python 3 中尝试 print string 时会得到确切的错误(当然,只要定义了 string)。

存在错误差异是因为 eval 是 (in 2.x) and still is (in 3.x) a function call. exec, on the other hand, was a statement in 2.x and made into a function in 3.x.