Re: [Python-Dev] cpython: Issue #12469: replace assertions by explicit if+raise
On Mon, 04 Jul 2011 18:06:53 +0200 victor.stinner <python-checkins@python.org> wrote:
http://hg.python.org/cpython/rev/7eef821ab20d changeset: 71197:7eef821ab20d user: Victor Stinner <victor.stinner@haypocalc.com> date: Mon Jul 04 18:06:35 2011 +0200 summary: Issue #12469: replace assertions by explicit if+raise
Instead of generic Exception, it would be better to use AssertionError. Regards Antoine.
Am 04.07.2011 18:23, schrieb Antoine Pitrou:
On Mon, 04 Jul 2011 18:06:53 +0200 victor.stinner <python-checkins@python.org> wrote:
http://hg.python.org/cpython/rev/7eef821ab20d changeset: 71197:7eef821ab20d user: Victor Stinner <victor.stinner@haypocalc.com> date: Mon Jul 04 18:06:35 2011 +0200 summary: Issue #12469: replace assertions by explicit if+raise
Instead of generic Exception, it would be better to use AssertionError.
What is the reason for this change anyway -- as far as I can see this code is never run with -O. Also I don't see how it relates to #12469. Georg
On Mon, Jul 4, 2011 at 9:23 AM, Antoine Pitrou <solipsis@pitrou.net> wrote:
On Mon, 04 Jul 2011 18:06:53 +0200 victor.stinner <python-checkins@python.org> wrote:
http://hg.python.org/cpython/rev/7eef821ab20d changeset: 71197:7eef821ab20d user: Victor Stinner <victor.stinner@haypocalc.com> date: Mon Jul 04 18:06:35 2011 +0200 summary: Issue #12469: replace assertions by explicit if+raise
Instead of generic Exception, it would be better to use AssertionError.
or in many cases given this was in unittests... use the self.assertFoo methods and avoid assert and if statements all together.
Regards
Antoine.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/greg%40krypto.org
Le lundi 04 juillet 2011 à 18:23 +0200, Antoine Pitrou a écrit :
On Mon, 04 Jul 2011 18:06:53 +0200 victor.stinner <python-checkins@python.org> wrote:
http://hg.python.org/cpython/rev/7eef821ab20d changeset: 71197:7eef821ab20d user: Victor Stinner <victor.stinner@haypocalc.com> date: Mon Jul 04 18:06:35 2011 +0200 summary: Issue #12469: replace assertions by explicit if+raise
Instead of generic Exception, it would be better to use AssertionError.
and
or in many cases given this was in unittests... use the self.assertFoo methods and avoid assert and if statements all together.
The code is running in a subprocess (python -c ...), not in an unittest.TestCase, so I cannot use self.assertFoo and it doesn't really matter if the exception is an Exception or an AssertionError.
What is the reason for this change anyway -- as far as I can see this code is never run with -O.
I'm not sure that the code will never be running using -O, so I prefer to use an explicit if+raise. I don't like the assert statement because it doesn't provide any information about the failure (content of the variables) by default. Victor
Exception is for catching, not raising. On Jul 4, 2011 11:57 AM, "Victor Stinner" <victor.stinner@haypocalc.com> wrote:
Le lundi 04 juillet 2011 à 18:23 +0200, Antoine Pitrou a écrit :
On Mon, 04 Jul 2011 18:06:53 +0200 victor.stinner <python-checkins@python.org> wrote:
http://hg.python.org/cpython/rev/7eef821ab20d changeset: 71197:7eef821ab20d user: Victor Stinner <victor.stinner@haypocalc.com> date: Mon Jul 04 18:06:35 2011 +0200 summary: Issue #12469: replace assertions by explicit if+raise
Instead of generic Exception, it would be better to use AssertionError.
and
or in many cases given this was in unittests... use the self.assertFoo methods and avoid assert and if statements all together.
The code is running in a subprocess (python -c ...), not in an unittest.TestCase, so I cannot use self.assertFoo and it doesn't really matter if the exception is an Exception or an AssertionError.
What is the reason for this change anyway -- as far as I can see this code is never run with -O.
I'm not sure that the code will never be running using -O, so I prefer to use an explicit if+raise. I don't like the assert statement because it doesn't provide any information about the failure (content of the variables) by default.
Victor
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
participants (5)
-
Antoine Pitrou -
Georg Brandl -
Gregory P. Smith -
Guido van Rossum -
Victor Stinner