This is a patch for bug #1443328. It fixes both failing cases from that bug (the second one is in the comments) and has tests for all the cases. On Windows with this patch applied, all test pass. If somebody is interested in rewriting this in C, he could use tp_slots field of the PyHeapTypeObject structure.