Re: [Pyobjc-dev] DeprecationWarning: Not all Objective-C arguments are present in the Python argume
Brought to you by:
ronaldoussoren
|
From: Ronald O. <ron...@ma...> - 2008-02-21 09:40:48
|
On 20 Feb, 2008, at 7:00, James R Eagan wrote:
> I've been using the following decorator in PyObjC 1.4 without
> problems, but now PyObjC 2.0 gives me a nice DeprecationWarning. Am
> I doing something naughty and/or dangerous? If so, is there a safer
> way to accomplish the same thing in PyObjC2?
The DeprecationWarning is bogus here. What this is trying to
accomplish is warn about mismatches between the Python signature and
Objective-C signature of a method, but this is giving false positives
on some occassions. In your case you get the warning because the
decorated function has a variable number of arguments.
I guess it is time to start working on a set of unittests for this
feature to find all types of false positives.
Ronald
>
>
> First, the decorator:
>
> def trap_exceptions(func):
> ''' Trap exceptions and prevent them from being passed along to
> the ObjC runtime. '''
> def trapper(self, *args, **kwargs):
> try:
> return func(self, *args, **kwargs)
> except:
> sys.stderr.write('Exception in %s: ' % (func.__name__))
> traceback.print_exception(*sys.exc_info())
> return trapper
>
> Typical usage is on an Objective-C entrypoint. e.g.:
>
> @trap_exceptions
> def performDragOperation_(self, sender):
> if self.delegate is not None \
> and
> self.delegate.respondsToSelector_('performDragOperation:'):
> return self.delegate.performDragOperation_(sender)
> return False
>
> This worked fine pre-Leopard. When an exception was thrown
> somewhere in (e.g.) performDragOperation_, I'd get a stack trace on
> the console and everything would carry along as if nothing
> happened. In PyObjC2, the decorator appears to behave as expected,
> but I also get this warning for every @trap_exceptions'ed method (at
> NIB load time):
>
> /System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/
> python/PyObjC/PyObjCTools/NibClassBuilder.py:219:
> DeprecationWarning: Not all Objective-C arguments are present in the
> Python argument-list of <unbound selector
> observeValueForKeyPath:ofObject:change:context: of CBIconView at
> 0x4f1fef0>
> return metaClass(name, bases, methods)
>
> Thanks!
> James
>
> PS: Thanks for all the work you've done on PyObjC 2.0. There are
> lots of wonderful improvements here! I'm very much looking forward
> to the Tiger backport. :-)
>
> --
> Doctors are sadists who like to play God and watch lesser people
> scream
> -- Bren MacGuff in "Juno"
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/_______________________________________________
> Pyobjc-dev mailing list
> Pyo...@li...
> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
|