Is it possible (and wise) to extend the None-type ?
Stef Mientki
stef.mientki at gmail.com
Wed Nov 26 16:36:03 EST 2008
Jason Scheirer wrote:
> On Nov 26, 11:40 am, Terry Reedy <tjre... at udel.edu> wrote:
>
>> Stef Mientki 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 _O
>>>
>>> So I would like to extend the None-type (if that's possible),
>>> with a dummy Skip() method.
>>>
>> def Skipper(object):
>> def Skip(): pass
>> skipper = Skipper()
>>
>> def _On_Menu_File_Open ( self, event = skipper ):
>> event.Skip ()
>>
>> etc.
>>
>
> I think this methods works best, but quite frankly, if a method is
> only two lines long, then you've likely got a code smell and no amount
> of over-design is going to cover for it.
>
Sorry I should have said that I only showed the relevant (to this issue)
part,
and this kind of if statements occurs quit a lot.
Probably I should not say this here on this list,
but to give you the whole truth,
I often forget the if-statement ( because it has really nothing to do
with the functionality I intend to write),
and then my program crashes (unexpected) :-(
cheers,
Stef
More information about the Python-list
mailing list