super

What exactly is super in Objective-C?

﹥>﹥吖頭↗ 提交于 2019-11-26 17:28:12
As far as I know, it's a pointer to the superclass. It's hard-wired with the superclass, and not dynamically figured out at runtime. Would like to know it more in detail... Anyone? super Essentially, it allows you to use the implementations of the current class' superclass. For the gritty details of the Objective-C runtime: [super message] has the following meaning: When it encounters a method call, the compiler generates a call to one of the functions objc_msgSend, objc_msgSend_stret, objc_msgSendSuper, or objc_msgSendSuper_stret. Messages sent to an object’s superclass (using the super

Don't I have to call super() in constructor when class extends Sprite in actionscript3?

不羁的心 提交于 2019-11-26 17:17:12
问题 I always don't call super() when I extends Sprite. But doesn't not calling super() cause any problem? Till now, I don't have any problem and I have never seen code which call super() in constructor which class extends Sprite. How about TextField? I don't have any problem about TextField, too. How to know whether I should call super() or not? 回答1: If flash doesn't detect a call to super() in your child constructor then flash will implicitly call super() before your child's constructor. So:

How is super() in Python 3 implemented?

南笙酒味 提交于 2019-11-26 14:35:46
问题 I'm wondering how is the new super in Python 3 implemented. This question was born in my head after I have made a small example and I got a strange error. I'm using Pyutilib Component architecture (PCA) and I've made my custom metaclass to drive the creation of another class: from pyutilib.component.core import implements, SingletonPlugin, PluginMeta, Interface class IPass(Interface): pass class __MetaPlugin(PluginMeta): def __new__(cls, name, baseClasses, classdict): print(cls, name,

Python super() raises TypeError

女生的网名这么多〃 提交于 2019-11-26 14:24:44
In Python 2.5, the following code raises a TypeError : >>> class X: def a(self): print "a" >>> class Y(X): def a(self): super(Y,self).a() print "b" >>> c = Y() >>> c.a() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in a TypeError: super() argument 1 must be type, not classobj If I replace the class X with class X(object) , it will work. What's the explanation for this? Cody Brocious The reason is that super() only operates on new-style classes , which in the 2.x series means extending from object : >>> class X(object): def a(self): print 'a' >>

When do I use super()?

别等时光非礼了梦想. 提交于 2019-11-26 12:48:48
I'm currently learning about class inheritance in my Java course and I don't understand when to use the super() call? Edit: I found this example of code where super. variable is used: class A { int k = 10; } class Test extends A { public void m() { System.out.println(super.k); } } So I understand that here, you must use super to access the k variable in the super-class. However, in any other case, what does super(); do? On its own? Calling exactly super() is always redundant. It's explicitly doing what would be implicitly done otherwise. That's because if you omit a call to the super

Is super() broken in Python-2.x? [closed]

心不动则不痛 提交于 2019-11-26 12:38:29
问题 It\'s often stated that super should be avoided in Python 2. I\'ve found in my use of super in Python 2 that it never acts the way I expect unless I provide all arguments such as the example: super(ThisClass, self).some_func(*args, **kwargs) It seems to me this defeats the purpose of using super() , it\'s neither more concise, or much better than TheBaseClass.some_func(self, *args, **kwargs) . For most purposes method resolution order is a distant fairy tale. Other than the fact that 2.7 is

super() raises “TypeError: must be type, not classobj” for new-style class

Deadly 提交于 2019-11-26 11:59:33
The following use of super() raises a TypeError: why? >>> from HTMLParser import HTMLParser >>> class TextParser(HTMLParser): ... def __init__(self): ... super(TextParser, self).__init__() ... self.all_data = [] ... >>> TextParser() (...) TypeError: must be type, not classobj There is a similar question on StackOverflow: Python super() raises TypeError , where the error is explained by the fact that the user class is not a new-style class. However, the class above is a new-style class, as it inherits from object : >>> isinstance(HTMLParser(), object) True What am I missing? How can I use super

Calling parent class __init__ with multiple inheritance, what&#39;s the right way?

♀尐吖头ヾ 提交于 2019-11-26 11:40:49
Say I have a multiple inheritance scenario: class A(object): # code for A here class B(object): # code for B here class C(A, B): def __init__(self): # What's the right code to write here to ensure # A.__init__ and B.__init__ get called? There's two typical approaches to writing C 's __init__ : (old-style) ParentClass.__init__(self) (newer-style) super(DerivedClass, self).__init__() However, in either case, if the parent classes ( A and B ) don't follow the same convention, then the code will not work correctly (some may be missed, or get called multiple times). So what's the correct way again?

Is it unnecessary to put super() in constructor?

淺唱寂寞╮ 提交于 2019-11-26 11:31:56
Isn't this one automatically put by the compiler if I don't put it in a subclass's constructor? That means I don't even need to care about it? In some articles they put it out. And if I've got one constructor with arguments, will this be the constructor, or does it take a constructor without argument list? cletus Firstly some terminology: No-args constructor: a constructor with no parameters; Accessible no-args constructor: a no-args constructor in the superclass visible to the subclass. That means it is either public or protected or, if both classes are in the same package, package access;

super() fails with error: TypeError “argument 1 must be type, not classobj” when parent does not inherit from object

这一生的挚爱 提交于 2019-11-26 11:06:49
I get some error that I can't figure out. Any clue what is wrong with my sample code? class B: def meth(self, arg): print arg class C(B): def meth(self, arg): super(C, self).meth(arg) print C().meth(1) I got the sample test code from help of 'super' built-in method. The class "C" is the Here is the error: Traceback (most recent call last): File "./test.py", line 10, in ? print C().meth(1) File "./test.py", line 8, in meth super(C, self).meth(arg) TypeError: super() argument 1 must be type, not classobj FYI, here is the help(super) from python itself: Help on class super in module __builtin__: