“So the case where the assumption fails may not be easily reproducable and the more information you can get post-mortem the better”
That’s true for rare corner cases or esoteric race conditions. Usually, when I see asserts it's just because I was just plain stupid. From: Python-list <python-list-bounces+gweatherby=uchc....@python.org> on behalf of Peter J. Holzer <hjp-pyt...@hjp.at> Date: Saturday, February 25, 2023 at 5:21 PM To: python-list@python.org <python-list@python.org> Subject: Re: Why doesn't Python (error msg) tell me WHAT the actual (arg) values are ? On 2023-02-25 21:58:18 +0000, Weatherby,Gerard wrote: > I only use asserts for things I know to be true. Yeah, that's what assers are for. Or rather for things that you *think* are true. > In other words, a failing assert means I have a hole in my program > logic. Yes, if you include your assumptions in your definition of "logic". > For that use, the default behavior –telling me which line the assert > is on, is more than sufficient. Depending on the circumstance, I’ll > re-run the code with a breakpoint or replace the assert with an > informative f-string Exception. That may not always be practical. Things that we know (or think) are true often have *are* true in most cases (otherwise we wouldn't think so). So the case where the assumption fails may not be easily reproducable and the more information you can get post-mortem the better. For example, in C on Linux a failed assertion causes a core dump. So you can inspect the complete state of the program. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | h...@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -- https://mail.python.org/mailman/listinfo/python-list