Is this Pythonic?

phil hunt zen19725 at zen.co.uk
Mon Aug 1 17:21:58 EDT 2005


On Mon, 01 Aug 2005 14:07:46 -0700, Erik Max Francis <max at alcyone.com> 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