# Boolean test switches that control whether a class variable of the metaclass # is added to the dir() result. # If the fix is not present, then enabling each one triggers the error # behavior; If none of them is enabled, the error behavior is not triggered. with_food = True # Add the 'normal' class attribute 'food' with_drink = True # Add the property-based class attribute 'drink' class FoodMeta(type): """Metaclass that adds its class attributes to dir() of classes using it.""" food = 'ham' # 'normal' class attribute @property def drink(cls): # property-based class attribute return 'beer' def __dir__(cls): ret = [name for name in cls.__dict__] # the normal list if with_food: ret += ['food'] if with_drink: ret += ['drink'] print "bug2.FoodMeta.__dir__(): return=%s" % (repr(ret),) return ret class Food(object): """docstring for Food class""" __metaclass__ = FoodMeta def diet(self): return "no!" if __name__ == '__main__': print "bug2: Calling help(Food):" help(Food)