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 pitrou
Recipients alexandre.vassalotti, belopolsky, lemburg, mark.dickinson, pitrou
Date 2010-06-29.08:36:45
SpamBayes Score 0.00036220544
Marked as misclassified No
Message-id <1277800603.3226.10.camel@localhost.localdomain>
In-reply-to <1277775942.55.0.746912271978.issue5180@psf.upfronthosting.co.za>
Content
> Well, this is not so obviously wrong as you make it sound.  If you
> look closer at object_new(), you will see that in sane situations it
> reduces to type->tp_alloc(type, 0) call.

Today, yes. But tomorrow it may entail additional operations.

> If such sanity check is necessary, I would rather check the flag
> explicitly in _pickle.c rather than having to generate dummy args and
> kwds to satisfy tp_new signature.

I find it better to "generate dummy args and kwds to satisfy tp_new
signature". I see no point in a partial inlining of an internal function
when we could call it instead.

> > So, IMO, the right thing to do would be to choose the first base
> > type that isn't a Python-defined class and use its tp_new:
> >
> >    staticbase = subtype;
> >    while (staticbase && (staticbase->tp_flags & Py_TPFLAGS_HEAPTYPE))
> >        staticbase = staticbase->tp_base;
> >
> > (these two lines are from tp_new_wrapper() in typeobject.c)
> >
> 
> This looks like overengineering to me.  I think 3.x should simply
> refuse to unpickle old style class instances into anything that is not
> subclassed in python directly from object.

Right, but it would lead to almost the same code... Since you have to
find the first non-Python base type and check that it is "object".

> It would be helpful at this point if you could provide a test case
> where tp_alloc logic does not work.

I'll try to find one.

> PPS: What is you opinion on the pickle.py trick of monkey patching
> __class__ on an instance of an empty class?  Do you think this can be
> fooled?

I don't think so.
History
Date User Action Args
2010-06-29 08:36:49pitrousetrecipients: + pitrou, lemburg, mark.dickinson, belopolsky, alexandre.vassalotti
2010-06-29 08:36:47pitroulinkissue5180 messages
2010-06-29 08:36:46pitroucreate