On Thu, Apr 11, 2019 at 8:15 AM Jeroen Demeyer <j.deme...@ugent.be> wrote: > > On 2019-04-11 00:09, Stefano Borini wrote: > > I occasionally found situations where I want to raise an exception for > > errors that can only arise because the developer made a mistake, for > > example: > > I use AssertionError for this. An assertion failure means "this is a > bug", so that seems the right choice to me. You don't need to use an > actual assert statement, you can manually raise AssertionError too. >
Agreed. It's worth noting that AssertionError isn't affected by the -O flag - only the assert *statement*. Also, anything that says "except AssertionError:" (outside of unit testing) should be considered a major bug, which in turn means that this should *only* be raised when you truly expect that normal usage cannot ever hit this. Which is perfect for the use-case you describe. 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/