forked from flypythoncom/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeta.py
More file actions
28 lines (22 loc) · 740 Bytes
/
meta.py
File metadata and controls
28 lines (22 loc) · 740 Bytes
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
26
27
28
from warnings import warn
class ReqStr(type):
def __init__(cls,name,bases,attrd):
super(ReqStr,cls).__init__(name,bases,attrd)
if "__str__" not in attrd:
raise TypeError("class overring __str__")
if "__repr__" not in attrd:
warn("class suggests __repr__",stacklevel = 3)
print "define ReqStr (meta)class \n"
class Foo(object):
__metaclass__ = ReqStr
def __str__(self):
return "instance of class",self.__class__.__name__
print "defined Foo class\n"
class Bar(object):
__metaclass__ = ReqStr
def __str__(self):
return self.__class__.__name__
print "defined Bar class\n "
class FooBar(object):
__metaclass__ = ReqStr
print "defined FooBar class \n"