Re:Understanding Python through its builtins
by robot_no_419 on Sunday October 10, 2021 @07:53PM
(#28823054)
Unless I'm misunderstanding, they are wrapping their asserts in try/catch blocks? That's... yikes.
[ Parent
| on HN ]
Re:Understanding Python through its builtins
by masklinn on Monday October 11, 2021 @03:06AM
(#28825611)
Most likely they just `assert` error conditions and let that blow up as error reporting, rather than write a full conditional and raise a custom exception.
I’ve been guilty of that in my own code when I just want to tell myself about an error.
Re:Understanding Python through its builtins
by andi999 on Monday October 11, 2021 @04:26AM
(#28826056)
Isnt just assert the error condition how assert is actually intended to be used?
Re:Understanding Python through its builtins
by masklinn on Monday October 11, 2021 @07:12AM
(#28827013)
Depends. The issue is that since `assert` is stripped out in “O” mode, if the codebase depends on `assert` for correctness… they’re not compatible.
Re:Understanding Python through its builtins
by andi999 on Tuesday October 12, 2021 @12:25AM
(#28836040)
What do you mean by depends on assert for correctness? How?
Re:Understanding Python through its builtins
by Doxin on Tuesday October 12, 2021 @07:30AM
(#28838464)
get_president_inside_bunker()
assert president_is_inside_bunker()
close_bunker_doors()
assert bunker_doors_are_closed()
send_nukes()
With asserts enabled this is fine. With asserts disabled you might start sending nukes while the president is still outside or the doors to the bunker are still open.