Inada Naoki <songofaca...@gmail.com> added the comment:

> Ironically, to let people prototype better, more efficient ways to deal with 
> namespace access, it should be possible to override an object used as a 
> namespace.

You can benchmark your prototype namespace object by regular Python code:

  d["name"]  # LOAD_GLOBAL
  d["name"] = 1  # STORE_GLOBAL

So I don't think no overriding blocks prototyping.


On the other hand, allowing overriding makes future optimizations difficult.  
For example:

```
>>> import dis
>>> def counter():
...     global _cnt
...     _cnt += 1
...     return _cnt
...
>>> dis.dis(counter)
  3           0 LOAD_GLOBAL              0 (_cnt)
              2 LOAD_CONST               1 (1)
              4 INPLACE_ADD
              6 STORE_GLOBAL             0 (_cnt)

  4           8 LOAD_GLOBAL              0 (_cnt)
             10 RETURN_VALUE
```

We may be possible to replace bytecode from `STORE_GLOBAL _cnt; LOAD_GLOBAL 
_cnt` into `DUP_TOP; STORE_GLOBAL _cnt`.

If we guarantee namespace overriding, it's very easy to break the guarantee 
while such optimization.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32615>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to