I was trying out NVI(Non-Virtual Interface) Idiom in python, and noticed that private(double underscore) methods don't seem to be acting as virtual.
class A(object):
def a(self):
print "in A.a"
self.b()
self.__b()
self._b()
def _b(self):
print "in A._b"
def __b(self):
print "in A.__b"
def b(self):
print "in A.b"
class B(A):
def __b(self):
print "in B.__b"
def b(self):
print "in B.b"
def _b(self):
print "in B._b"
>>> a=A()
>>> b=B()
>>> a.a()
in A.a
in A.b
in A.__b
in A._b
>>> b.a()
in A.a
in B.b
in A.__b
in B._b
I am guessing this may have been because of name mangling for double underscore methods, but it is counter-intuitive. Further, confusion arises from python documentation "(For C++ programmers: all methods in Python are effectively virtual.)".