FAQ Database Discussion Community


TypeError: Super does not take Key word arguments?

python,class,inheritance,super
First, here is my code: class Enemy(): def __init__(self, name, hp, damage): self.name = name self.hp = hp self.damage = damage def is_alive(self): """Checks if alive""" return self.hp > 0 class WildBoar(Enemy): def __init__(self): super(WildBoar, name="Wild Boar", hp=10, damage=2).__init__() class Marauder(Enemy): def __init__(self): super(Marauder, name="Marauder", hp=20, damage=5).__init__() class Kidnappers(Enemy): def...

Python: How to call super when the class itself has a decorator?

python,inheritance,wrapper,decorator,super
I need to call the inherited class to get it's content and methods to work. But I also have a class decorator assigned to my wrapper classes. I have a lot of wrapper classes and want them to be as short as possible, that's why I try to get this...

Should remove(Object) be remove(? super E)

java,generics,collections,super,contravariance
In this answer, I tried to explain why the Collection method add has the signature add(E) while remove is remove(Object). I came up with the idea that the correct signature should be public boolean remove(? super E element) And since this is invalid syntax in Java, they had to stick...

AttributeError: Type Object 'Ned' has no Attribute 'attack'?

python,class,oop,super,attributeerror
Here's my code: Classes: class Player(object): """Base class for the player""" def __init__(self, name, armour, attack): self.name = name self.armour = armour self.attack = attack class Ned(Player): """The main player""" def __init__(self): super(Ned, name="Ned", armour=10, attack=3).__init__() Line Causing the Issue: entities.Ned.attack += 3 When I run this, I get: AttributeError:...

Python self and super in multiple inheritance

python,inheritance,self,super,method-resolution-order
In Raymond Hettinger's talk "Super considered super speak" at PyCon 2015 he explains the advantages of using super in Python in multiple inheritance context. This is one of the examples that Raymond used during his talk: class DoughFactory(object): def get_dough(self): return 'insecticide treated wheat dough' class Pizza(DoughFactory): def order_pizza(self, *toppings):...

meaning of the super keyword in the parent class python

python,object,super
I do not understand the meaning of the super keyword when it is not used in a child class. The question comes from this class here that I found on a git hub project where I am working (the link is https://github.com/statsmodels/statsmodels/pull/2374/files) Look for example at the fit method where...

“Super” issue: “error: '(' expected”

java,for-loop,arraylist,super
Hello and thanks for reading! I use a "for" to read every object in an arraylist, and want to check the string that returns the function getType() for each object, which exists in the extended class of the objects. for(int i=0; i<cat.items.size(); i++) { if ( cat.items.get(i).super.getType().equals(type) ); { However,...

python problems with super

python-2.7,pyside,maya,super
Ok so I'm having a bit of a problem with the code below. It works as is but if I try to change the part with the comment about me not being able to get super to work correctly to. pipeline_class_call = super(Error_Popup,self) broken_file_w_whats_wrong = pipeline_class_call.whats_wrong_with_file() or to broken_file_w_whats_wrong =...

ruby: calling super without having a parent class

ruby,initialization,parent,super
I have a class which overrides self.new and calls super in it, but the class doesn't derive from antoher class. So what exactly does the call? class Test attr_reader :blatt def self.new(blatt, quellformat, &block) begin # why can't I call initialize(blatt,quellformat) here? # when I try this, it only prints...

Extending JFrame - how does “super” keyword work?

java,object,jframe,super
I've made a class that extends JFrame, and in my classes constructor, to set the title I can either use: super("title"); setTitle("title"); or just create a JFrame object i.e: JFrame f = new JFrame("title); How does the compiler differentiate from all of these to conclude the same thing? I know...

How to invoke base-class method from second-level inherited class? [duplicate]

java,super
This question already has an answer here: Calling super super class method 7 answers Let's say I have a base class called Vehicle, and another class called Car that extends it. Finally I have a class Luxury that extends Car. I know I can use the keyword super to...

Java default constructor without initialization

java,constructor,default,super
I have a class similar to the below one with all static methods. Hence the class was not initialized while used in other classes. I have to check a condition before invoking any static methods from this class. Even if i add a default constructor it will not get called....

Why do we call super() in constructor

java,constructor,super
We have a constructor like this: public statusArea() { super(); add(pageIdentifier); } Why do we call super in it?...

Can't use “super” to refer to a name that was brought in by “use” from another crate

module,rust,super,use
I am using super inside a module to refer to names in the parent namespace. However, I cannot get this to work when I refer to a name in the parent namespace that was brought in with a use statement. What am I doing wrong? // crate mylib pub fn...

Why we using super() when inherit is already enough

python,class,python-3.4,super
I saw an example that is about super(); class Class1: def __init__(self): pass def name(self): return "My name is" class Class2(Class1): def __init__(self): pass def name(self): return super(Class2, self).name() + " Tom" #now lets call the object. b = Class2() print(b.name()) #Output is 'My name is Tom' Here is another...

Python: Calling the __init__() method of a base class using super() when it requires arguments [duplicate]

python,inheritance,super
This question already has an answer here: Python super() raises TypeError 3 answers I am trying to call the __init__() method in a superclass, where said method takes arguments, but it doesn't seem to be working. Please see the code below: >>> class A: def __init__(self, param1, param2): self._var1...

Conversion from java to c# super(ClassName.this) argument

java,c#,super,nested-class
I have the following code: public ClassC { public class ClassA extends ClassB<T> { /** * @uml.property name="index" */ private int index; public ClassA() { super(ClassC.this); index = 0; } } I have found that, ClassName.this is needed from inner classes to get to the outer class instance of this,...

Java - Sorting out subclass from ArrayList of superclass

java,sorting,inheritance,arraylist,super
I have an ArrayList which contains objects of the super class and some subclass objects. Let's call them subclass1 and subclass2. Is there a way I can go ArrayList and discern which objects are SuperClass, subclass1 and subclass2. So I can put them into ArrayList and ArrayList. This is an...

Why dual __init__ in python?

python,oop,inheritance,super
I am investigating python oop style. I have seemed __init__ construction method as below. I did't see this style before. Why use dual __init__ methods as in this stuff? ex- class MinimumBalanceAccount(BankAccount): def __init__(self, minimum_balance): BankAccount.__init__(self) self.minimum_balance = minimum_balance def withdraw(self, amount): if self.balance - amount < self.minimum_balance: print 'Sorry,...

Java generics: collection of super of super of some type

java,generics,superclass,super
Consider the following self-contained sample: import java.util.*; class TestApplication { interface Type<C> { Collection<Type<? super C>> getSuperTypes(); } static class Test<C> { private final Type<? super C> mySuperType = get( null ); public Collection<Type<? super C>> getSuperTypes() { Collection<Type<? super C>> superTypes = new ArrayList<>(); superTypes.add( mySuperType ); //directly passing...

What is invoking the super class constructor here?

java,inheritance,constructor,superclass,super
I came across this code while looking for exam prep questions. I don't understand what is invoking the superclass constructor in this code? The output is ---> feline cougar cc THL public class Feline{ public String type = "f "; public Feline(){ System.out.print("feline "); } } - public class Cougar...

Difference between “super” and “super do |u|” using context of Devise

ruby-on-rails,ruby,ruby-on-rails-4,devise,super
Ok so I think I get what super does standalone. Basically in Devise, if Users::RegistrationsController < Devise::RegistrationsController, then on any action, having a super will first call the logic for that same named action in the parent Devise::RegistrationsController, before then calling what you've written. In other words... class Devise::RegistrationsController def...