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 serhiy.storchaka
Recipients eric.smith, gvanrossum, serhiy.storchaka, ztane
Date 2016-05-04.17:57:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1462384637.01.0.830586541215.issue26906@psf.upfronthosting.co.za>
In-reply-to
Content
The problem is that format() fails for instances of some classes, because the type still is not initialized. The simplest example -- list iterator.

>>> format(iter([]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Type listiterator doesn't define __format__

After forcing type initialization (for example by getting any type's attribute), format() becomes working.

>>> type(iter([])).foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'listiterator' has no attribute 'foo'
>>> format(iter([]))
'<listiterator object at 0xb708d0ec>'

I afraid that format() is just one example, and there are other functions or operators that don't work or work incorrectly if the type was not initialized.

init_types-2.7.patch adds explicit initialization of 38 types (I didn't check that all of them need this, but I suppose they do). This is large patch, and I'm not sure that it fixes all types.

Other way is to try to initialize the type just in _PyType_Lookup if it is not initialized. This is simple change, but a comment in _PyType_Lookup warns me. I found that this solution was already applied as an attempt to fix issue551412, but then reverted. Since you seem to be the most knowledgeable with this code, I'm asking you what was wrong with this approach and how we can fix this.

Python 3.x also suffers from this bug, but it is reproduced with less types. For example it isn't reproduced for list iterator. I don't know why.
History
Date User Action Args
2016-05-04 17:57:17serhiy.storchakasetrecipients: + serhiy.storchaka, gvanrossum, eric.smith, ztane
2016-05-04 17:57:17serhiy.storchakasetmessageid: <1462384637.01.0.830586541215.issue26906@psf.upfronthosting.co.za>
2016-05-04 17:57:16serhiy.storchakalinkissue26906 messages
2016-05-04 17:57:16serhiy.storchakacreate