thautwarm <yaoxiansa...@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 <rep...@bugs.python.org> <https://bugs.python.org/issue34880> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com