|
|
|
|
|
by calvinlough
5029 days ago
|
|
The code to call super is awkward. Instead of saying super(MyClass, self).foo(), I would rather just say super.foo(). Having to specify self or cls as the first argument of an instance or class method. This one is weird when you are learning Python because you don't pass in the first variable but it gets magically inserted for you. Creating a class method using a method decorator. Using a decorator to do something like this seems like a hack to me. Not having a clean way to specify what all the instance variables are outside of the constructor. People with a java background are used to putting instance variable declarations as the first thing inside a class definition. In Python, these will be static variables. This seems weird and inconsistent with the how method declarations work (methods only become class methods when a decorator is used). BTW, I like Python. |
|
That's been changed in Python 3. Although it brings other issues.
> Creating a class method using a method decorator. Using a decorator to do something like this seems like a hack to me.
Why? Even more so, why is a decorator more of a hack than adding a new keyword (java) or special-casing method declaration (ruby) itself? Note that you can also create class methods without decorators if you wish to, by using a metaclass (I believe the method won't be accessible from the instance though)
> This seems weird and inconsistent with the how method declarations work.
It's actually very coherent: every binding created in the class scope is collected and set on the class object, as if passed as the third argument to `type`. That's it. Some objects (functions) are processed a bit more, but they still end up in the same place.
> methods only become class methods when a decorator is used
That's because the decorator is basically a flag to tell the attribute-resolution process to handle this method differently from the normal method-resolution process.