Is it possible (and wise) to extend the None-type ?

Chris Rebert clp at rebertia.com
Wed Nov 26 19:05:50 CET 2008


On Wed, Nov 26, 2008 at 9:55 AM, Stef Mientki <stef.mientki at gmail.com> wrote:
> hello,
>
> I've the idea that I always have a lot of useless code in my programs,
> like the next example.
>
>  def _On_Menu_File_Open ( self, event = None ):
>   if event :
>    event.Skip ()
>
> instead of
>
>  def _On_Menu_File_Open ( self, event = None ):
>  event.Skip ()
>
> So I would like to extend the None-type (if that's possible),

It's not. You can't graft new methods onto NoneType (a.k.a.
type(None)), and you can't subclass NoneType either.
You might be interested in the recipe for a "Null" type:
http://code.activestate.com/recipes/68205/

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com

> with a dummy Skip() method.
>
> Is it wise to do ?
> If not what are the disadvantages ?
>
> thanks,
> Stef Mientki
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list