Is this Pythonic?

phil hunt zen19725 at
Mon Aug 1 23:21:58 CEST 2005

On Mon, 01 Aug 2005 14:07:46 -0700, Erik Max Francis <max at> wrote:
>Yes, but raise NotImplementedError instead of Exception.  Another trick 
>you can use is to prevent people from instantiating the abstract class:
>	class Foo:
>	    def __init__(self):
>	        if self.__class__ is Foo:
>	            raise NotImplementedError
>	        ...
>	    def bar(self):
>	        raise NotImplementedError

That's a clever trick, but it's obvious from the code that the class 
is intended to be abstract, so if people are stupid enough to shoot 
themselves in the foot by creating an instance, I don't feel like 
adding extra code to protect themselves from their stupidity.

Email: zen19725 at zen dot co dot uk

More information about the Python-list mailing list