[Python-Dev] PEP 310 and exceptions
Nick Coghlan
ncoghlan at gmail.com
Sun Apr 24 08:42:18 CEST 2005
Shane Hathaway wrote:
> Nick Coghlan wrote:
>
>> Which means finding a different name for '__else__'. Two possibilities that
>> occur to me are '__ok__' or '__no_except__'. The latter makes a fair
>> amount of sense, since I can't think of a way to refer to the thing other
>> than as a 'no exception' handler.
>
>
> While we're on the subject of block handler method names, do the method names
> need four underscores? 'enter' and 'exit' look better than '__enter__' and
> '__exit__'.
It's traditional for slots (or pseudo-slots) to have magic method names. It
implies that the methods are expected to be called implicitly via special syntax
or builtin functions, rather than explicitly in a normal method call. The only
exception I can think of is the 'next' method of the iterator protocol. That
method is often called explicitly, so the exception makes sense.
For resources, there doesn't seem to be any real reason to call the methods
directly - the calls will generally be hidden behind the 'with' block syntax.
Hence, magic methods.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-Dev
mailing list