Calling the __call__ superclass method

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

Contains an HMM class that inherits from BayesianModel , which is a new-style class. Each of them has a __call__ method. HMM __call__ is for invoking the Bayesian model on line 227:

 return super(HMM,self)(PriorProbs) 

However, this fails with the exception of

 super(HMM,self) 

not callable.

What am I doing wrong?

+4
source share
1 answer

You need to directly call the __call__ method:

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

This applies to any hook that needs to call an overridden method in a superclass.

super() returns a proxy object with a .__getattribute__() method that looks for the superclass hierarchy for the attribute you are looking for. This proxy alone cannot be called; it does not have its own __call__ method. Only when you explicitly look at the __call__ method as an attribute of this proxy can python find the right implementation for you.

+4
source

Source: https://habr.com/ru/post/1433255/


All Articles