This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author skrah
Recipients ezio.melotti, mark.dickinson, skrah, ubershmekel
Date 2010-07-01.11:10:34
SpamBayes Score 2.349646e-05
Marked as misclassified No
Message-id <20100701111004.GA21563@yoda.bytereef.org>
In-reply-to <1277981243.63.0.63762409083.issue9136@psf.upfronthosting.co.za>
Content
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}
>>>
History
Date User Action Args
2010-07-01 11:10:36skrahsetrecipients: + skrah, mark.dickinson, ezio.melotti, ubershmekel
2010-07-01 11:10:34skrahlinkissue9136 messages
2010-07-01 11:10:34skrahcreate