[Python-Dev] Should assert continue to do a LOAD_GLOBAL on AssertionError?
brett at python.org
Fri Oct 5 17:52:39 EDT 2018
On Wed, 3 Oct 2018 at 19:39, Benjamin Peterson <benjamin at python.org> wrote:
> On Wed, Oct 3, 2018, at 08:59, Steven D'Aprano wrote:
> > On the bug tracker, there's a discussion about the current behaviour of
> > the assert statement, where shadowing AssertionError will change the
> > behaviour of the assertion.
> > https://bugs.python.org/issue34880
> > Currently, assert does a LOAD_GLOBAL on AssertionError, which means if
> > you shadow the name, you get a different exception. This behaviour goes
> > back to Python 1.5.
> > I'm looking for guidance here, is this the intended behaviour, or an
> > accident? Should it be changed to better match other builtins?
> The behavior certainly has been relied on historically by py.test. By
> replacing builtins.AssertionError, you can improve the error message of the
> AssertionError by, e.g., inspecting the failing frame. py.test's code to do
> this was deleted in 2016, but other code bases may still be relying on this
> hack. It's probably okay to change the behavior in 3.8 with the
> understanding that a revert may be necessary if some clever hack surfaces.
I like Guido's reasoning that syntax probably shouldn't be affected by
overloads unless otherwise documented as so, and Benjamin's approach to
solving it for 3.8 and then potentially reverting if it breaks too much.
> Python-Dev mailing list
> Python-Dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev