Re: [Pyobjc-dev] TypeError: cannot change a method
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2009-07-16 07:21:03
|
Could you post some code that shows what you're trying to do? I haven't checked the source code yet, but one reason to be careful about overwriting methods in Cocoa classes is that will affect the actual Cocoa class as wel. Footnote [0] refers to replacing a method in an instance by something else, e.g.: o = NSObject.alloc().init() o.description = 42 That's not allowed because this can lead to very hard to diagnose bugs, and the people that are most likely to run into those are people new to PyObjC that translate existing ObjC sample code into Python (the reason of that is that ObjC has different namespaces for methods and instance variables, while Python has only a single namespace for both of them). BTW, PyObjC breaks another Python idiom as well: "Explicit is better than implicit.", and completely on purpuse ;-) Ronald On 16 Jul, 2009, at 4:30, Daniel Miller wrote: > My testing framework for the app I've been developing (previously with > PyObjC 1.4, now attempting to migrate to PyObjC 2) is giving lots of > errors due to a restriction in PyObjC 2 that methods cannot be > overwritten [0]. My testing framework mocks Cocoa API calls to verify > that the calls are being made as expected without actually hitting > Cocoa (which would cause all sorts of unwanted side-affects). My first > question is about circumventing this read-only method restriction for > my tests. Is it possible to (temporarily?) make PyObjC methods > writable? Maybe through some hack that would only be activated as a > pre-test setup task, allowing me to overwrite methods just during the > testing phase? > > My second question is why such a restriction has been added? I'm not > trying to start a flame war here, so please don't get that idea. > Python is generally very liberal in what it allows one to do, even > potentially damaging things such as shooting ones self in the foot: > > "Python culture tends towards "we're all consenting adults here". If > you > attempt to shoot yourself in the foot, you should get some kind of > warning that perhaps it is not what you really want to do, but if you > insist, hey, go ahead, it's your foot!" [1] > > "...this is Python, where we vigorously defend the right to shoot > ourselves in the foot." [2] > > Is there any particular technical reason why PyObjC tries harder- > than-normal-for-Python to protect me from doing things that most > people probably do not want to do? Thanks in advance for taking time > to answer my questions. > > ~ Daniel > > [0] http://www.mail-archive.com/mat...@li.../msg05035.html > [1] http://mail.python.org/pipermail/tutor/2006-December/051569.html > [2] http://www.gossamer-threads.com/lists/python/python/753888#753888 > > > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited > time, > vendors submitting new applications to BlackBerry App World(TM) will > have > the opportunity to enter the BlackBerry Developer Challenge. See > full prize > details at: http://p.sf.net/sfu/Challenge > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |