I agree, assert should be a built-in function, rather than a keyword. It was overlooked when print() tore the world apart with 3.0, so I think it's safe to say that it have had very little impact.
I'm all for changing it. It will just have to go through __future__ purgatory for a decade or so, before I'm happy telling people to no longer rely on asserting that their tuple is non-empty.
Not cause the parameters to be evaluated before the function was called (we don't have lisp macros here),
Not cost function call cost to the no-op/ pass-ish function.
Prevent alias assignments from it, or prevent being reassigned to, like True and False used to suffer from. Both of which would complicate either the magical-ness of the assert-as-function, or allow for very anti-Pythonic code.
Assert-as-keyword with varying behavior currently solves both.
As for mistakes like 'assert (False, 'oops')', well, you got a unit test proving that the assert actually trips when it ought? If you did, it wouldn't stay this spelled buggy for long.
This is what allows the optimization to happen. Knowing when the assert name is seen that it is the real assert. The only way to do it that is consistent with the rest of python is have it as a keyword.
21
u/Anonymous_user_2022 Jan 21 '22
I agree, assert should be a built-in function, rather than a keyword. It was overlooked when print() tore the world apart with 3.0, so I think it's safe to say that it have had very little impact.
I'm all for changing it. It will just have to go through __future__ purgatory for a decade or so, before I'm happy telling people to no longer rely on asserting that their tuple is non-empty.