self is normally used when referring to an instance of a class, not the class itself. Also, in your example usage for __new__ you have used cls instead of self, which is not present. You might want to correct that.
Absolutely correct @gabriel
per the Python documentation:
" The new(cls[,...]) method is called first to create a new instance of class, cls. It is a static
method that takes the class of which an instance was requested as its first argument.
The return value of new( ) should be the new object instance(usually an instance of class(cls)). "
Semantics of interpretation of the programming language: It is a class 'static' method. :)>
Hi, I'm Swastik Baranwal, a software developer from New Delhi, India passionate about open-source contribution, Gopher, Pythoneer, Compiler Design and DevOps.
self
is normally used when referring to an instance of a class, not the class itself. Also, in your example usage for__new__
you have usedcls
instead ofself
, which is not present. You might want to correct that.__new__
should usecls
and notself
as it is a "static" method that belongs to the class, not the instance.See docs.python.org/3/reference/datamo...
Absolutely correct @gabriel
per the Python documentation:
" The new(cls[,...]) method is called first to create a new instance of class, cls. It is a static
method that takes the class of which an instance was requested as its first argument.
The return value of new( ) should be the new object instance(usually an instance of class(cls)). "
Semantics of interpretation of the programming language: It is a class 'static' method. :)>
Yes, its right and I had changed it a long time back!
It's actually a classmethod, not a static method but
cls
is still the recommended name