On Tue, Nov 28, 2017 at 1:12 PM, Ivan Pozdeev via Python-ideas <python-ideas@python.org> wrote: > The `assert' statment was created the same as in previous languages like > C/C++: a check to only do in debug mode, when you can't yet trust your code > to manage and pass around internal data correctly. Examples are array bounds > and object state integrity constraints. > > Unlike C, Python does the aforementioned checks all the time, i.e. it's > effectively always in "debug mode". Furthermore, validation checks are an > extremily common use case. > > I have been using assert in my in-house code for input validation for a long > time, the only thing preventing me from doing the same in public code is the > fact that it only raises AssertionError's while library code is expected to > raise TypeError or ValueError on invalid input.
Actually, Python does have a way of disabling assertions (the -O flag), so they should be treated the same way they are in C. Assertions should not be used as shorthands for "if cond: raise Exc" in the general case. ChrisA _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/