Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoking the __call__ method of a superclass

http://code.google.com/p/python-hidden-markov/source/browse/trunk/Markov.py

Contains a class HMM, which inherits from BayesianModel, which is a new-style class. Each has a __call__ method. HMM's __call__ method is meant to invoke BayesianModel's at line 227:

return super(HMM,self)(PriorProbs)

However, this fails with an exception

super(HMM,self)

is not callable.

What am I doing wrong?

like image 840
Pete Bleackley Avatar asked Sep 09 '12 21:09

Pete Bleackley


1 Answers

You need to invoke the __call__ method itself, explicitly:

return super(HMM, self).__call__(PriorProbs)

This applies to any hook that needs to call the overridden method on the superclass.

super() returns a proxy object, with a .__getattribute__() method that searches the super-class hierarchy for the attribute you are searching for. This proxy itself is not callable; it has no __call__ method of it's own. Only when you explicitly look up the __call__ method as an attribute of that proxy can python find the right implementation for you.

like image 58
Martijn Pieters Avatar answered Oct 27 '22 17:10

Martijn Pieters