-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta.py
46 lines (31 loc) · 1.06 KB
/
meta.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
from warnings import warn
class ReqStrSugRepr(object):
def __init__(cls, name, bases, attrd):
super(ReqStrSugRepr, cls).__init__(
name, bases, attrd)
if '__str__' not in attrd:
raise TypeError(
"Class requires overriding of __str__()")
if '__repr__' not in attrd:
warn(
'Class suggests overriding of __repr__()\n',
stacklevel=3)
print '*** Defined ReqStrSugRepr (meta)class\n'
class Foo(object):
__metaclass__ = ReqStrSugRepr
def __str__(self):
return 'Instance of class:', \
self.__class__.__name__
def __repr__(self):
return self.__class__.__name__
print '*** Defined Foo class\n'
class Bar(object):
__metaclass__ = ReqStrSugRepr
def __str__(self):
return 'Instance of class:', \
self.__class__.__name__
print '*** Defined Bar class\n'
class FooBar(object):
__metaclass__ = ReqStrSugRepr
print '*** Defined FooBar class\n'