Mark Shannon <[email protected]> added the comment:
In Python 3.9 the binding is more late-ish binding, than true late binding.
Because globals['__builtins__'] is cached for each function activation,
executing functions don't see updates.
Example:
>>> def f():
... print(len("test"))
... bltns = f.__globals__["__builtins__"]
... if hasattr(bltns, "__dict__"):
... bltns = bltns.__dict__
... new = bltns.copy()
... new["len"] = lambda x : 7
... f.__globals__["__builtins__"] = new
... print(len("test"))
...
>>>
>>> f()
4
4
>>> f()
7
7
True late binding would print:
>>> f()
4
7
>>> f()
7
7
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue42990>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com