[Python-3000] Generic function PEP won't make it in time

Jim Jewett jimjjewett at gmail.com
Tue Apr 24 19:35:08 CEST 2007

On 4/24/07, Talin <talin at acm.org> wrote:
> In what is considered "good style" for such languages, protected helper
> methods ought to have different names than the methods which invoke
> them. So for example, you might have the following:

>     /// Abstract base class for hashable object
>     class Hashable {
>     public:
>        /// Declare abstract hash method
>        virtual int GetHash() const = 0;
>     protected:
>        /// Protected helper method
>        int DefaultHashFunc() { return 0; }
>     };

This is exactly why diamond inheritance is tricky.  Try this with a
cooperative method, such as save_state.

    def save_state(self):
        # Save my own state, then...

        # Do call the helper method if no one else will...
        # Do not call the helper method in case someone else does...

The solution is to avoid making the "top" of the hierarchy a
singleton.  Calling it (through super) is OK.  It might even be
helpful, or it might be a no-op -- but it is safe to call through

The reason to mark it @abstract is to say that the implementation
isn't complete yet.  For hashable, you may never call super at all;
for save_state, you should always call it.


More information about the Python-3000 mailing list