Re: 10.8, 10.9, NSDocument, TypeError, "cannot change a method"

Ronald Oussoren <[email protected]> Thu, 29 Aug 2013 13:37:58 +0200
Newsgroups gmane.comp.python.pyobjc.devel
Message-ID <[email protected]>
On 28 Aug, 2013, at 15:25, Erik van Blokland <[email protected]> wrote:

> Hi
> 
> I'm aware this is a bit of a long shot, but maybe someone recognises this issue. 
> 
> I have a python application generated with pyobjc on OSX 10.8.
> 	- Stock python Python 2.7.2 (default, Oct 11 2012, 20:14:37)
> 	- presumably also a stock objc 2.3.2a0, (at /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/objc/__init__.py)
> 
> On 10.7 and 10.8 I can get a new window when I select New from the menu. 
> On 10.9 (the current developer release) I get an exception, "cannot change a method" - see below. The app continues to run, but there isn't much of a traceback. 
> 
> Looking at the dump, I get the impression something goes wrong when NSDocumentController calls newDocument: My NSDocument subclass doesn't contain anything suspicious. I think I'm using up to date calls for reading and writing. Methods in my NSDocument subclass:  
> 	init
> 	readFromURL_ofType_error_
> 	writeSafelyToURL_ofType_forSaveOperation_error_
> 	makeWindowControllers
> 	+ a couple of callbacks for menus. 
> 
> I've tested this with two independent projects, both get the same exception. 
> Any guesses would be welcome, thanks.

The exception you're getting (``TypeError('cannot change a method')``) is raised when you try to set an instance attribute with the same name as a method, for example:

:>>> from Cocoa import NSObject
:>>> o = NSObject.alloc().init()
:>>> o.description = 42
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot change a method

This means that your document class problably has an attribute that has the same name as a method that is new in OSX 10.9.

BTW. Have you tried ``objc.setVerbose(1)``? That should print more information when converting exceptions from Python to ObjC.  I guess I should also change the code that raises the exception to include more information (such as the name of the attribute).

Ronald


> Erik
> 
> Exception Name: OC_PythonException
> Description: <type 'exceptions.TypeError'>: cannot change a method
> User Info: {
>   "__pyobjc_exc_traceback__" = "<traceback object at 0x112ea8680>";
>   "__pyobjc_exc_type__" = "<type 'exceptions.TypeError'>";
>   "__pyobjc_exc_value__" = "TypeError('cannot change a method',)";
> }
> 
> 0   CoreFoundation                      0x00007fff886878ce __exceptionPreprocess + 174
> 1   libobjc.A.dylib                     0x00007fff8f656f51 objc_exception_throw + 43
> 2   CoreFoundation                      0x00007fff8872d619 -[NSException raise] + 9
> 3   _objc.so                            0x000000010acb1366 PyObjCFFI_MakeClosure + 4418
> 4   libffi.dylib                        0x00007fff91c02a1f ffi_closure_unix64_inner + 509
> 5   libffi.dylib                        0x00007fff91c0211e ffi_closure_unix64 + 70
> 6   AppKit                              0x00007fff888e0b0f -[NSDocumentController newDocument:] + 36
> 7   AppKit                              0x00007fff88af90da -[NSApplication sendAction:to:from:] + 327
> 8   AppKit                              0x00007fff88c1d548 -[NSMenuItem _corePerformAction] + 394
> 9   AppKit                              0x00007fff88c1d234 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 117
> 10  AppKit                              0x00007fff8893e72d -[NSMenu _internalPerformActionForItemAtIndex:] + 35
> 11  AppKit                              0x00007fff8893e5a5 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 104
> 12  AppKit                              0x00007fff88c16442 NSSLMMenuEventHandler + 716
> 13  HIToolbox                           0x00007fff8ad8a9a4 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 892
> 14  HIToolbox                           0x00007fff8ad89f67 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 385
> 15  HIToolbox                           0x00007fff8ad9f4f0 SendEventToEventTarget + 40
> 16  HIToolbox                           0x00007fff8add4380 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 420
> 17  HIToolbox                           0x00007fff8ad7b818 SendMenuCommandWithContextAndModifiers + 59
> 18  HIToolbox                           0x00007fff8ad7b7ba SendMenuItemSelectedEvent + 178
> 19  HIToolbox                           0x00007fff8ad7b697 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 94
> 20  HIToolbox                           0x00007fff8ad58d95 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 718
> 21  HIToolbox                           0x00007fff8ad58261 _HandleMenuSelection2 + 446
> 22  AppKit                              0x00007fff88ae8109 _NSHandleCarbonMenuEvent + 284
> 23  AppKit                              0x00007fff88a13f1e _DPSNextEvent + 2170
> 24  AppKit                              0x00007fff88a1328b -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
> 25  AppKit                              0x00007fff88a0b53c -[NSApplication run] + 553
> 26  AppKit                              0x00007fff889b5563 NSApplicationMain + 940
> 27  _AppKit.so                          0x000000010cbfcbbe init_AppKit + 8609
> 28  Python                              0x000000010ab025a9 PyEval_EvalFrameEx + 9244
> 29  Python                              0x000000010ab00147 PyEval_EvalCodeEx + 1934
> 30  Python                              0x000000010ab068df _PyEval_SliceIndex + 989
> 31  Python                              0x000000010ab0263a PyEval_EvalFrameEx + 9389
> 32  Python                              0x000000010ab00147 PyEval_EvalCodeEx + 1934
> 33  Python                              0x000000010aaff9b3 PyEval_EvalCode + 54
> 34  Python                              0x000000010ab3bc70 PyParser_ASTFromFile + 299
> 35  Python                              0x000000010ab3bd3c PyRun_FileExFlags + 165
> 36  Python                              0x000000010aafa830 _PyBuiltin_Init + 4737
> 37  Python                              0x000000010ab025a9 PyEval_EvalFrameEx + 9244
> 38  Python                              0x000000010ab00147 PyEval_EvalCodeEx + 1934
> 39  Python                              0x000000010ab068df _PyEval_SliceIndex + 989
> 40  Python                              0x000000010ab0263a PyEval_EvalFrameEx + 9389
> 41  Python                              0x000000010ab00147 PyEval_EvalCodeEx + 1934
> 42  Python                              0x000000010aaff9b3 PyEval_EvalCode + 54
> 43  Python                              0x000000010ab3bc70 PyParser_ASTFromFile + 299
> 44  Python                              0x000000010ab3bd3c PyRun_FileExFlags + 165
> 45  Python                              0x000000010ab3b726 PyRun_SimpleFileExFlags + 410
> 46  Superpolator                        0x000000010a988e79 main + 5965
> 47  Superpolator                        0x000000010a987cad main + 1409
> 48  libdyld.dylib                       0x00007fff8d81160d start + 1
> 49  ???                                 0x0000000000000001 0x0 + 1
> ------------------------------------------------------------------------------
> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
> Discover the easy way to master current and previous Microsoft technologies
> and advance your career. Get an incredible 1,500+ hours of step-by-step
> tutorial videos with LearnDevNow. Subscribe today and save!
> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
> _______________________________________________
> Pyobjc-dev mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk