super

How Python's Super() works in multiple inheritance for superclasses?

How Python's Super() works in multiple inheritance for superclasses? Question: I’m trying to understand how super works in python’s multiple inheritance for the superclasses, for example in the code below: class First(): def __init__(self, parm1, **kwargs): super().__init__(**kwargs) self.parm1 = parm1 self.parm3 = ‘one’ class Second(): def __init__(self, parm2 = ‘zero’, **kwargs): super().__init__(**kwargs) self.parm2 = parm2 …

Total answers: 2

python3 super() new style autocompletion in PyCharm

python3 super() new style autocompletion in PyCharm Question: With python3 we no longer need to explicitly set the parent class when calling super: def __init__(self): super().__init__() But it seems that PyCharm doesn’t know it, because when I try to autocomplete super for some method, it uses old style and I receive this: def setUp(self): super(AutocompleteTestCase, …

Total answers: 1

What does super with 2 arguments do

What is the use of super with arguments? Question: super() is a function in python used to acces members of a super class but sometimes it takes some arguments, what does does super with arguments do. If either takes a class, a class and object or two classes other than no argument What is the …

Total answers: 1

Getting private attribute in parent class using super(), outside of a method

Getting private attribute in parent class using super(), outside of a method Question: I have a class with a private constant _BAR = object(). In a child class, outside of a method (no access to self), I want to refer to _BAR. Here is a contrived example: class Foo: _BAR = object() def __init__(self, bar: …

Total answers: 2

Is IntelliJ Python 3 inspection "Expected a dictionary, got a dict" a false positive for super with **kwargs?

Is IntelliJ Python 3 inspection "Expected a dictionary, got a dict" a false positive for super with **kwargs? Question: I use Python 3 and want to wrap argparse.ArgumentParser with a custom class that sets formatter_class=argparse.RawDescriptionHelpFormatter by default. I can do this successfully, however IntelliJ IDEA 2017.1 with Python Plugin (PyCharm) gives a warning for the …

Total answers: 3

What's the difference between super() and Parent class name?

What's the difference between super() and Parent class name? Question: Is there a difference between using super() and using the parent class name directly? For example: class Parent: def __init__(self): print(“In parent”) self.__a=10 class Child(Parent): def __init__(self): super().__init__() # using super() Parent.__init__(self) # using Parent class name c=Child() Is there internally a difference between super().__init__() …

Total answers: 2

Inheriting from a namedtuple base class

Inheriting from a namedtuple base class Question: This question is asking the opposite of Inherit namedtuple from a base class in python , where the aim is to inherit a subclass from a namedtuple and not vice versa. In normal inheritance, this works: class Y(object): def __init__(self, a, b, c): self.a = a self.b = …

Total answers: 4

Why my python subclass doesn't recognize attribute from super class?

Why my python subclass doesn't recognize attribute from super class? Question: I was testing inheritance of python, I’ve got this: __metaclass__=type class b: def __init__(s): s.hungry=True def eat(s): if(s.hungry): print “I’m hungry” else: print “I’m not hungry” class d(b): def __init__(s): super(b,s).__init__() def __mysec__(s): print “secret!” obj=d() obj.eat() There’s runtime error as: Traceback (most recent …

Total answers: 3

python multiple inheritance passing arguments to constructors using super

python multiple inheritance passing arguments to constructors using super Question: Consider the following snippet of python code class A(object): def __init__(self, a): self.a = a class B(A): def __init__(self, a, b): super(B, self).__init__(a) self.b = b class C(A): def __init__(self, a, c): super(C, self).__init__(a) self.c = c class D(B, C): def __init__(self, a, b, c, …

Total answers: 4

How to call super method from grandchild class?

How to call super method from grandchild class? Question: I am working with some code that has 3 levels of class inheritance. From the lowest level derived class, what is the syntax for calling a method 2 levels up the hierarchy, e.g. a super.super call? The “middle” class does not implement the method I need …

Total answers: 5