[Python-checkins] r43367 - in python/trunk/Lib: contextlib.py test/test_contextlib.py
Guido van Rossum
guido at python.org
Tue Mar 28 19:47:33 CEST 2006
On 3/28/06, Nick Coghlan <ncoghlan at gmail.com> wrote:
> phillip.eby wrote:
> > Author: phillip.eby
> > Date: Tue Mar 28 02:07:24 2006
> > New Revision: 43367
> >
> > Modified:
> > python/trunk/Lib/contextlib.py
> > python/trunk/Lib/test/test_contextlib.py
> > Log:
> > Fix contextlib not copying function attributes
> >
> >
> > Modified: python/trunk/Lib/contextlib.py
> > ==============================================================================
> > --- python/trunk/Lib/contextlib.py (original)
> > +++ python/trunk/Lib/contextlib.py Tue Mar 28 02:07:24 2006
> > @@ -78,6 +78,7 @@
> > try:
> > helper.__name__ = func.__name__
> > helper.__doc__ = func.__doc__
> > + helper.__dict__ = func.__dict__
> > except:
> > pass
> > return helper
>
> I realise it isn't likely to be an issue for contextmanager in particular, but
> I believe it's generally better to avoid referencing the original dict
> directly and instead do:
> helper.__dict__.update(func.__dict__)
>
> The checked in version may do strange things if the decorator doesn't hold the
> sole reference to func (i.e., it's being applied as a function, rather than
> using decorator syntax).
Yeah, explicit copying seems better for mutables.
Also, shouldn't each transfer of metadata be given its own try/except?
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-checkins
mailing list