[issue34880] About the "assert" bytecode

Steven D'Aprano report at bugs.python.org
Wed Oct 3 11:36:57 EDT 2018


Steven D'Aprano <steve+python at pearwood.info> added the comment:

On Wed, Oct 03, 2018 at 01:56:00PM +0000, Eric V. Smith wrote:
> I think this is a bug that should be fixed.

Supporting this position, shadowing other exceptions doesn't change the 
exception generated by the interpreter:

py> TypeError = None
py> 1 + "a"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'

On the other hand, this has been the behaviour going back to Python 1.5, 
it is hard to see why this is worse than any other example of shadowing. 
I don't think there's anything in the documentation that says that 
assert *shouldn't* do a LOAD_GLOBAL on AssertionError.

Hence this would be an enhancement rather than a bug fix.

> And, I think a broader discussion on python-dev might be useful, too, 
> in order to get more opinions.

I agree. I think we need to clarify the intent here, and then decide 
that if it is a bug, should we bother fixing it in pre-3.8 versions?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34880>
_______________________________________


More information about the Python-bugs-list mailing list