import contextlib

class Pituh(object):
    def __enter__(self):
        return "pithu"

    def __exit__(self, exc_type, exc_val, exc_tb):
        print("exit")
        
    def kok(self):
    	print("kok")

class Spam(contextlib.AbstractContextManager, list):
    def __exit__(self, exc_type, exc_value, traceback):
        for i in self:
            i.__exit__(exc_type, exc_value, traceback)


spam = Spam()
spam.append(Pituh())
spam.append(Pituh())

with spam as s:
    kok = s[0]
    print(type(kok))
    kok.kok()