[Python-Dev] PEP 318 bake-off?

Bob Ippolito bob at redivi.com
Thu Apr 1 14:33:24 EST 2004

On Apr 1, 2004, at 2:08 PM, Guido van Rossum wrote:

>>> What I'm asking (especially of Phillip) is to collect a set of
>>> realistic method declarations using decorators; we can then
>>> collectively format these using any of the possible syntaxes, and see
>>> how they look.
>> I'd be happy to scrounge up some samples from existing code using
>> 'property' and 'classmethod' as well as some of PEAK's decorators, 
>> and I
>> definitely think that Jack Diedrich and Bob Ippolito's samples should 
>> be
>> included as well.
>> Important question, though: do we include code bodies, or just use 
>> 'pass'
>> for the bodies?  If we include the body, how much of the body?  
>> Should we
>> include entire classes, especially if the class itself needs a 
>> decorator,
>> and multiple methods have decorators?
> Why not provide the bodies, for added realism?
> (I still think class decorators are a separate case, and much weaker
> -- you can do this by having a single 'decoratable' metaclass and
> setting __decorators__ = [...] in the class body.)

Here's something I wrote today.. it's a delegate for the exception 
handling mechanism so you can listen in on (any of) the exceptions that 
ObjC throws whether or not they are caught by something else.. the 
Python->PyObjC exceptions are logged as tracebacks and the ObjC 
exceptions are thrown over to atos so they turn into human-readable 
stack traces.

As you can see, it's rather ugly with regular old Python syntax.

class PyObjCDebuggingDelegate(NSObject):
     def exceptionHandler_shouldLogException_mask_(self, sender, 
exception, aMask):
             if isPythonException(exception):
                 if self.verbosity() & LOGSTACKTRACE:
                 return nsLogPythonException(exception)
             elif self.verbosity() & LOGSTACKTRACE:
                 return nsLogObjCException(exception)
                 return False
             print >>sys.stderr, "*** Exception occurred during 
exception handler ***"
             return True
     exceptionHandler_shouldLogException_mask_ = 

     def exceptionHandler_shouldHandleException_mask_(self, sender, 
exception, aMask):
         return False
     exceptionHandler_shouldHandleException_mask_ = 

the objc.selector signatures say that they return a char (a BOOL, 
actually), the following @: represents "self" and the selector (the 
"method name"), the next two @@ say that the sender and exception 
arguments are both ObjC objects, and the trailing I means that aMask is 
an unsigned int.


More information about the Python-Dev mailing list