We're all consenting adults, so I won't judge you for doing so. But if you have reason for doing so, I will also assume that you know the caveats, just like you will have to, if you redefine print().
How will the compiler step know I redefined assert? Right now assert has 0 runtime impact with -O because the statement is not even present in the bytecode, if assert becomes a function python will always need to do a lookup.
Nononono, there will never be a version of Python where you can overwrite assert - assert has to continue to be a statement, even if this tuple hack is accepted.
24
u/[deleted] Jan 21 '22
Oh! No, I disagree with that.
assertoccupies a unique position where if Python is not run in debug mode, none of the statement goes off at all.So you can put some pretty heavy tests in there, and then in production, turn on optimization with
-Oor-OOand they won't run.