[issue34880] About the "assert" bytecode
thautwarm
report at bugs.python.org
Wed Oct 3 06:29:30 EDT 2018
thautwarm <yaoxiansamma at gmail.com> added the comment:
Reply to this:
> How is that different from every other case of shadowing a builtin?
>
> len = 45
> print(len("hello world"))
```
AssertionError = 42
assert 1 != 2
```
`assert` implicitly invokes `AssertionError`, while `len` does that explicitly. That is to say, simply changing a global variable breaks the work of a keyword.
Another difference is that shadow builtins could be resumed in the
nested functions without something like `globals()` or `exec(..., {})`, while you cannot perform this to the breakage of `assert`:
```
len = 1
def g():
from builtins import len
return len([1, 2, 3])
g() # => 3
AssertionError = +1
def f():
from builtins import AssertionError
assert False
f() # boooom
```
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34880>
_______________________________________
More information about the Python-bugs-list
mailing list