usr bin env python This meta-class enforces an identifier minimum leng

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/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"