[Python-Dev] [Python-checkins] Daily reference leaks (d7e490db8d54): sum=61494

Steven D'Aprano steve at pearwood.info
Wed Oct 21 18:41:42 EDT 2015


On Wed, Oct 21, 2015 at 10:10:56AM -0700, Ethan Furman wrote:
> On 10/21/2015 08:53 AM, Random832 wrote:
> 
> >If a pure python class can cause a reference leak, doesn't that mean it
> >is only a symptom rather than the real cause? Or is it that the use of
> >@object.__new__ is considered "too clever" to be worth fixing?
> 
> Where can I find out more about using `object.__new__` as a decorator?

How about the interactive interpreter?

py> @object.__new__
... class X:
...     pass
...
py> X
<__main__.X object at 0xb7b4dacc>


Consider the pre-decorator-syntax way of writing that:

class X:
    pass

X = object.__new__(X)

That's a way of setting X = X(), except that it only works for X a class 
(can't decorate a function this way), and it avoids calling the __init__ 
method.


-- 
Steve


More information about the Python-Dev mailing list