python: enforce that a class method is only called from within another class method?
<p>I have a class with two methods A and B. The class will be subclassed. Is there an elegant way to enforce that B() is only ever called on an object of the class from within the A() method?</p>

<p>Let's constrain it and say that A() is only called in one place but subclasses implement A() and can optionally call B() within that. One way I thought of doing this was to wrap the A() call with setting a global variable that says it's ok to call B(), and B() would check this variable when it's invoked. This doesn't seem elegant though.</p>

<p>Any suggestions?</p>
