r/Python • • Jan 21 '22

News PEP 679 -- Allow parentheses in assert statements

https://www.python.org/dev/peps/pep-0679/
209 Upvotes

112 comments sorted by

View all comments

Show parent comments

9

u/Anonymous_user_2022 Jan 21 '22

Oh! No, I disagree with that.

It has to be. It's opening a stinky can of worms to treat the 2-tuple Truthy other than all of the other kind of Truthies there are.

There's nothing wrong with letting the hypothetical assert() function being a nop, when -O is present.

0

u/jmcs Jan 21 '22

What happens if I try to define my own assert function in that case, like I can do with print in python 3?

4

u/Anonymous_user_2022 Jan 21 '22

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().

3

u/jmcs Jan 21 '22

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.

→ More replies (0)