6 ms·
Unfortunatly you often can't use -o because of the 3rd party libs that didnt' get the memo and use assert for error checking. We still have -X dev and sys.fla
by BiteCode_dev 5y ago
Unfortunatly you often can't use -o because of the 3rd party libs that didnt' get the memo and use assert for error checking.
We still have -X dev and sys.flags but it's runtime only.
- alshel 5y agoCare to name any 3rd party libs in particular?
- zbentley 5y agoDjango Rest Framework.
- BiteCode_dev 5y agoNope, I just remember my server crashing years ago so I stopped ever since. Would be interesting to scan pypi and check if this is still a thing. Maybe create a bot warning lib authors.
- zarzavat 5y agoSeems like a better idea would be to make a separate flag "--remove-assertions" for people who desire that.
- BiteCode_dev 5y ago"-o" is mostly "--remove-assertions" already, so that wouldn't help. While today's use case for assert is unit testing, the actual killer feature of the keyword is that it's removed only from prod. The idea is that you can write things like function contracts, that are expensive, but only exist in dev. Now, if one of you dependencies use assert for something they expect to still be in prod, which is the problem we are talking about in the first place, "-o" or "--remove-assertions" will strip their assert too, breaking their code, and hence, yours since it depends on it.
- athrowaway3z 5y agoBefore this thread i had no idea assert was debug only in python. Another solution would be to accept the current role of assert as quick error checking and add in debug_assert to indicate a conditional error check. The biggest issue with that approach is that a majority will suddenly ask "Wait, python has a debug mode?"
- BiteCode_dev 5y agoNot because the -o mode also remove any block testing on "__debug__", and that's a very useful thing as well. The original feature is perfect. But there is 5 good years of educating users so it can be used.
- andi999 5y agoI still do not understand what the problem is and what users need to know. So assert throws and exception in debug mode and is 'commented out' in production, right? So the problem is some vendors ship libs that have failing asserts so cannot run in debug mode?
- human_error 5y agoStarlette, SQLAlchemy.
- robot_no_419 5y agoUnless I'm misunderstanding, they are wrapping their asserts in try/catch blocks? That's... yikes.
- masklinn 5y agoMost 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.
- andi999 5y agoIsnt just assert the error condition how assert is actually intended to be used?
- masklinn 5y agoDepends. The issue is that since `assert` is stripped out in “O” mode, if the codebase depends on `assert` for correctness… they’re not compatible.
- andi999 5y agoWhat do you mean by depends on assert for correctness? How?
- Doxin 5y agoget_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.
- andi999 5y agoThanks! I never thought anybody would do such a thing.