class_new.py 416 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
class A:
    def __new__(cls):
        print("A.__new__")
        return super(cls, A).__new__(cls)

    def __init__(self):
        pass

    def meth(self):
10
        print('A.meth')
11
12
13
14
15

#print(A.__new__)
#print(A.__init__)

a = A()
16
17
18
19
a.meth()

a = A.__new__(A)
a.meth()
20
21
22
23

#print(a.meth)
#print(a.__init__)
#print(a.__new__)
24
25
26
27

# __new__ should automatically be a staticmethod, so this should work
a = a.__new__(A)
a.meth()