Re: [Pyobjc-dev] Protocol support
Brought to you by:
ronaldoussoren
From: Bob I. <bo...@re...> - 2005-02-18 05:12:10
|
On Feb 17, 2005, at 3:59 PM, Ronald Oussoren wrote: > > On 17-feb-05, at 4:47, Bob Ippolito wrote: > >> I've committed basic (formal) Protocol support. It can be used just >> like informal protocols: >> >> import objc >> from Foundation import * >> NSLocking = objc.protocolNamed('NSLocking') >> class Foo(NSObject, NSLocking): >> pass >> >> # I can't wait until this is FINALLY FIXED, it is the thing that >> annoys me most about PyObjC >> >>> Foo.pyobjc_classMethods.conformsToProtocol_(NSLocking) >> 1 >> >>> Foo.alloc().init().conformsToProtocol_(NSLocking) >> 1 >> >> It could use (at least) the following improvements: >> - Protocols are not type checked. Anything in the base list that is >> a PyObjCObject will get chunked into the protocol list. Will >> probably crash if you do something really stupid (though there's >> plenty of that in PyObjC anyway) > Protocols are now typechecked. > > I've also added some unittests for this feature. > >> - Protocols can not be created from PyObjC >> - selectors don't benefit from the Protocol information like they do >> for informal protocols >> - PyObjC doesn't verify that you implement the protocol like it does >> for informal protocols >> - objc.protocolNamed is probably pretty slow, should use a lookup hash > These still need to be implemented. I just added an objc.protocolsForClass, and re-implemented protocolNamed in Python using a lookup hash but with the same search algorithm. Could be faster if it cached classes it has seen, but I guess maybe a category could change the behavior of that so this is safer. The other three more important things are still unimplemented :) -bob |