def obj_from_classtype(klass): """Create an object of ClassType klass. We aren't allowed (by the pickle protocol) to call __init__() on the new object, so we have to be careful.""" return instance_noinit(klass)
class New_slots_no_init(int): __slots__ = ('this', 'that') def work(self): # prove object is alive inc() class New_no_slots_no_init(int): def work(self): # prove object is alive inc() #print "There should be NO text between the following lines:" #print "----------------------------------------------------" olist = [] olist.append(instance_noinit(Old_noinit)) olist.append(instance_noinit(Old_init)) if pyconfig.Have_Slots(): olist.append(instance_noinit(New_slots_and_init)) olist.append(instance_noinit(New_slots_no_init)) olist.append(instance_noinit(New_init_no_slots)) olist.append(instance_noinit(New_no_slots_no_init)) for o in olist: o.work() if (pyconfig.Have_Slots() and COUNTER != 6) or \ (not pyconfig.Have_Slots() and COUNTER != 2): print("Bad count") raise
from gnosis.util.introspect import instance_noinit class Old_noinit: pass class Old_init: def __init__(self): print "Init in Old" class New_slots_and_init(int): __slots__ = ('this','that') def __init__(self): print "Init in New w/ slots" class New_init_no_slots(int): def __init__(self): print "Init in New w/o slots" class New_slots_no_init(int): __slots__ = ('this','that') class New_no_slots_no_init(int): pass print "----- This should be the only line -----" instance_noinit(Old_noinit) instance_noinit(Old_init) instance_noinit(New_slots_and_init) instance_noinit(New_slots_no_init) instance_noinit(New_init_no_slots) instance_noinit(New_no_slots_no_init)
print("Init in Old") class New_slots_and_init(int): __slots__ = ('this', 'that') def __init__(self): print("Init in New w/ slots") class New_init_no_slots(int): def __init__(self): print("Init in New w/o slots") class New_slots_no_init(int): __slots__ = ('this', 'that') class New_no_slots_no_init(int): pass print("----- This should be the only line -----") instance_noinit(Old_noinit) instance_noinit(Old_init) instance_noinit(New_slots_and_init) instance_noinit(New_slots_no_init) instance_noinit(New_init_no_slots) instance_noinit(New_no_slots_no_init)
class New_slots_no_init(int): __slots__ = ('this','that') def work(self): # prove object is alive inc() class New_no_slots_no_init(int): def work(self): # prove object is alive inc() #print "There should be NO text between the following lines:" #print "----------------------------------------------------" olist = [] olist.append( instance_noinit(Old_noinit) ) olist.append( instance_noinit(Old_init) ) if pyconfig.Have_Slots(): olist.append( instance_noinit(New_slots_and_init) ) olist.append( instance_noinit(New_slots_no_init) ) olist.append( instance_noinit(New_init_no_slots) ) olist.append( instance_noinit(New_no_slots_no_init) ) for o in olist: o.work() if (pyconfig.Have_Slots() and COUNTER != 6) or \ (not pyconfig.Have_Slots() and COUNTER != 2): raise "Bad count" #print "----------------------------------------------------"