forked from UWPCE-PythonCert/ProgrammingInPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcool_meta.py
More file actions
30 lines (19 loc) · 786 Bytes
/
Copy pathcool_meta.py
File metadata and controls
30 lines (19 loc) · 786 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
29
30
"""
Complete do-nothing metaclass example
It serves to show when each special method of the metaclass is called.
"""
class CoolMeta(type):
def __new__(meta, name, bases, dct):
print('Creating class in CoolMeta.__new__', name)
return super().__new__(meta, name, bases, dct)
def __init__(cls, name, bases, dct):
print('Initializing class in CoolMeta.__init__', name)
super().__init__(name, bases, dct)
def __call__(cls, *args, **kw):
print('calling CoolMeta to instantiate ', cls)
return type.__call__(cls, *args, **kw)
class CoolClass(metaclass=CoolMeta):
def __init__(self):
print('And now my CoolClass object exists')
print('everything loaded, instantiate a CoolClass instance now')
foo = CoolClass()