Message326959
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
``` |
|
Date |
User |
Action |
Args |
2018-10-03 10:29:30 | thautwarm | set | recipients:
+ thautwarm, steven.daprano, vtheno athena |
2018-10-03 10:29:30 | thautwarm | set | messageid: <1538562570.07.0.545547206417.issue34880@psf.upfronthosting.co.za> |
2018-10-03 10:29:30 | thautwarm | link | issue34880 messages |
2018-10-03 10:29:30 | thautwarm | create | |
|