Your question isn't really specific to python but could be applied to many OO languages like C++ or C#. I haven't yet come across a hard rule but same thought did occur to me from time to time.
So what follows is my opinion:
- Private method - what only class C should know about and/or use. No one else
- Protected methods - what deriving classes should know about and/or use.
- Public methods - what external code should know about and/or use.
So in your example, I would make the function protected but in documentation of class C make it very explicit that deriving classes are not intended to call this function directly. Rather they should implement it and let the base class decide when it is appropriate to call it.
In other words, you expect deriving class to provide implementation. So at this point, nothing is stopping the person coding that class from calling that code. Even if you manage to somehow "mark it private", since that person wrote that code once, he'll write it again, or find another way to run it if that's what he/she really wants to do.
As far as what's pythonic. I'm not a python expert, but I believe this is the language convention:
- no underscore prefix (i.e. f() ) = public function
- double underscore (i.e. __f() ) = private function
- single underscore (i.e. _f() ) = internal use function
Python relies heavily on convention rather than language to keep people from accessing private date. Nothing is really hidden, but when you prefix function name with "__", the interpret will "mangle" that function name. The reason it does that is to discourage (not prevent) people from writing client code that calls private functions:
c = C()
... will result in interpreter telling you that the function doesn't exist. But if someone really wants to call your private function, they'll just write:
c._C__foo() # mangled name (I don't remember exact
# naming rules, but point is the same)
I wouldn't recommend using private functions in python for protected ones. It seems the language really intended "__" to signal to outside world, including deriving classes, "don't touch".
In your case, I would use single "_" to signal that the function is not for public/external consumption but rather should only be used, or overridden by someone who has enough knowledge about the class (i.e. presumably implementer of the deriving class is more knowledgeable about some internal details than someone writing client code).
Few sources that mention the use of "__" (double-underscore) for private symbols: