<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 2, 2016 at 6:32 PM, Ryan Gonzalez <span dir="ltr"><<a href="mailto:rymg19@gmail.com" target="_blank">rymg19@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span><p dir="ltr"><br>
On May 2, 2016 10:55 AM, "Guido van Rossum" <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>> wrote:<br>
><br>
> On Mon, May 2, 2016 at 8:38 AM, Ryan Gonzalez <<a href="mailto:rymg19@gmail.com" target="_blank">rymg19@gmail.com</a>> wrote:<br>
>><br>
>> I feel like you just brought up the exact issue. Assertions should *never* be used for things like this. Because, one day, some stupid idiot is going to use assertions to perform some sort of data validation, someone else will use that library with -O, and the world will explode.<br>
><br>
> That's a very strong opinion, and a bit of a doomsday scenario. I hear worries about this a lot, but I've never heard a story from someone to whom this actually happened.<br>
>><br>
>> It's just far too attractive to use but far too easy to misuse.<br>
><br>
> The thing is, assert exists and is not going away. People are writing these asserts today (there are still many in asyncio). In many cases the assert is not guarding against bad data or user input, but simply against a confused caller. The assumption is that once the program is debugged enough to go to production (where you use -O) the need for the asserts has gone down enough that it doesn't matter the checks are gone -- the confused call site has long been found during tests and fixed. </p>
</span><p dir="ltr">I would still prefer the proposal that requires the errors to derive from AssertionError</p></blockquote><div><div class="gmail_quote">The proposal I'm making is the exact opposite (allow a different exception than AssertionError) so I'm not sure I understand your objection.</div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><p dir="ltr">, since there *are* people that will use this for some sort of data validation. </p></blockquote><div>Personally I never used asserts for data validation. Usually they are used:</div><div><br></div><div>#1 in unit tests, if you don't like using the verbose unittest's self.assert* APIs</div><div>#2 in application code as an extra safety to make sure, e.g., that the function's caller is passing the "right things", that an attribute has a certain value at some point, etc.</div><div><br></div><div>Note that #2 is meant to help the developer(s), not the final user. It's something which is there as a guard against possible mistakes but not much more, and to my understanding this is how most people feel about "assert"s.  Could allowing to raise a specific and "more correct" exception type as a one-liner be an incentive to use "assert" to validate user input? I don't know, but my impression is that:<br><br></div><div>#1 most people are "educated" enough to know that assert is usually not meant to validate user input</div><div>#2 very few people use -O (e.g. I believe I never used it myself) </div><div>#3 I expect whoever uses -O is supposed to be aware of what are the implications of it</div><div><br></div></div>-- <br><div><div dir="ltr"><div>Giampaolo - <a href="http://grodola.blogspot.com" target="_blank">http://grodola.blogspot.com</a></div><div><br></div></div></div>
</div></div>