#!/usr/bin/env python3 # By William Schwartz wkschwartz at gmail dot com "Demonstrate that the __prepare__ method of a metaclass is implicitly a static method." import unittest class TestImplicitStaticMethod(unittest.TestCase): def setUp(self): class Meta(type): def __prepare__(*args, **kwds): assert any(isinstance(arg, type) and issubclass(arg, type) for arg in args), "No type subclass passed to __prepare__" return {} self.Meta = Meta @unittest.expectedFailure def runTest(self): class K(object, metaclass=self.Meta): pass class TestExplicitClassMethod(unittest.TestCase): def setUp(self): class Meta(type): @classmethod def __prepare__(*args, **kwds): assert any(isinstance(arg, type) and issubclass(arg, type) for arg in args), "No type subclass passed to __prepare__" return {} self.Meta = Meta def runTest(self): class K(object, metaclass=self.Meta): pass if __name__ == '__main__': unittest.main(verbosity=2)