Re: [Pyobjc-dev] [ pyobjc-Bugs-836247 ] NSWindow.contentRectForFrameRect_styleMask_ not a class meth
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-11-05 10:00:16
|
Managment summary: use 'NSWindow.pyobjc_classMethods.contentRectForFrameRect_styleMask_' to call the class method. On 5 nov 2003, at 9:23, Bob Ippolito wrote: > On Nov 4, 2003, at 10:56 PM, SourceForge.net wrote: > >> Bugs item #836247, was opened at 2003-11-05 03:56 >> Message generated for change (Tracker Item Submitted) made by Item >> Submitter >> You can respond by visiting: >> https://sourceforge.net/tracker/? >> func=detail&atid=114534&aid=836247&group_id=14534 > > This bug exposes a fairly obnoxious problem in the current > implementation of PyObjC: there are not separate namespaces for class > and instance methods, so you end up with stupid problems when you have > some class that implements the same selector for both the instance and > class. There's a lot of pretty common selectors that are like this: > +[NSObject description] > -[NSObject description] > .. etc .. I noticed. It is already possible to call both methods, although not necessarily in a very convenient way: NSObject.foo() # Instancemethod, or if that does not exist classmethod NSObject.pyobjc_classMethods.foo() # Classmethod NSObject.pyobjc_instanceMethods.foo() # Instancemethod At the time we ran into this issue I couldn't find any methods where it would be usefull to override the class method, it is therefore not possible to override the class method at the moment. > > I did discover a workaround, which is > ClassObject.bothClassAndInstanceMethod(ClassObject).. for example: > >>> NSObject.description(NSObject) > u'<NSObject: 0xa0a04e40>' That's more a bug than a feature... > > Ideally one would be able to do NSObject.description().. which means > that the descriptor has to know about these "class or instance" > methods. It's also, as far as I know, not possible to override the > class implementation for a selector if an instance implementation > exists (from Python). Note that it is currently not possible to know of 'NSObject.description' refers to the class or instance method due to the way types are implemented in Python: obj.description() is basically implemented as: obj.__class__.description(obj) And furthermore Cocoa classes should 'feel' as much as Python classes as possible, it should therefore be possible to call 'NSObject.description(obj)'. > > So my question is, how the heck do we approach this? It seems that > the current selector objects/descriptors need to be changed quite a > bit in order to facilitate this, especially allowing one to do it from > Python. Perhaps we can change the selector function to take a class > function, instance function, or both.. and throw away isClassMethod. > We can add a flag on the selector that says "I have both a class and > an instance". I'm pretty new to these internals.. so, Ronald, do you > want to handle this one? Or give me some ideas as to how this should > be done? Is it necessary to be able to override class methods? My gut feeling is that it would be easy-ish to change objc.selector() to allow something like this: class FooClass (NSObject): def _cls_description(cls): return "FooClass class" def _inst_description(self): return "FooClass instance" description = objc.selector(selector="description", clsImp=_cls_description, instImp=_inst_description) del _cls_description, _inst_description This is pretty ugly, but at least would make it possible to override both the class and instance method without introducing an additional class. However, I don't think this is worth the effort unless someone has a real use case. Ronald |