#!/usr/bin/env python
# This meta-class enforces an "identifier minimum length" rule
class VerboseClass(type):
def __init__(self, name, bases, dict):
# make sure attribute names are extra long
for key, value in dict.items():
# ignore special methods
if key.startswith('__') and key.endswith('__'):
continue
if len(key) < 16:
raise TypeError, "Attribute names must be at least 16 letters long"
type.__init__(self, name, bases, dict)
class Verbose(object):
__metaclass__ = VerboseClass
class Foo(Verbose):
def a_very_simple_method_called_bar(self):
print "Hello world"
def spam(self): # this line will cause exception
print "Sorry"