Message109043
Mark Dickinson <report@bugs.python.org> wrote:
>
> Mark Dickinson <dickinsm@gmail.com> added the comment:
>
> class Context(object):
> def __init__(self):
> for name, val in locals().items():
> setattr(self, name, val)
>
>
> Isn't this dodgy anyway, since 'name' and 'val' end up going into locals()? I wonder why the RuntimeError *isn't* raised for a normal 'Context()' call (i.e., not via profile).
Indeed, and it seems to depend on how name and vals are used:
... print(locals())
...
{'name': '__builtins__', 'val': <module 'builtins' (built-in)>, '__builtins__': <module 'builtins' (built-in)>, '__package__': None, 'Context': <class '__main__.Context'>, '__name__': '__main__', '__doc__': None}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: dictionary changed size during iteration
... pass
...
>>> locals()
{'name': '__doc__', 'val': None, '__builtins__': <module 'builtins' (built-in)>, '__package__': None, 'Context': <class '__main__.Context'>, '__name__': '__main__', '__doc__': None}
>>> |
|
Date |
User |
Action |
Args |
2010-07-01 11:10:36 | skrah | set | recipients:
+ skrah, mark.dickinson, ezio.melotti, ubershmekel |
2010-07-01 11:10:34 | skrah | link | issue9136 messages |
2010-07-01 11:10:34 | skrah | create | |
|