I find when __init__
method lacks self
parameter, only if there is no instantiation of this class, the compiler won't complain:
$ cat test.py
#!/usr/bin/python
class A():
def __init__():
print("A()")
$ ./test.py
But if there is a instantiation, the running time error will occur:
$ cat test.py
#!/usr/bin/python
class A():
def __init__():
print("A()")
A()
$ ./test.py
Traceback (most recent call last):
File "./test.py", line 6, in <module>
A()
TypeError: __init__() takes 0 positional arguments but 1 was given
Per my understanding, __init__()
seems no use because it can't make any instance. So why doesn't the Python compiler enforce limitation such as when no self
parameter in __init__
function, it will show error message? Is it reasonable? Or I miss something.