Forum Archive

create_obj_class ... two issues

JonB

two issues:
1) when using on_main_thread to decorate an objc method, create_objc_class thinks there are no arguments. I think @dgelessus has pointed out the issue with wraps not being correct. Not sure if on_main_thread is needed on things that get called from the main thread anyway?

2) the methods argument does not seem to allow instance methods. (raised an exception when adding, complaining of the extra argument, which was self). I believe the code needs to toss out the first (self) argspec.arg for methods that have an __im_func__ attribute.

JonB

also, related to objc in general, a suggestion:
please expose _get_objc_classname() in ObjCInstance's dir method, so it will be autocompleted...I can never remember the name, and it is useful!

dgelessus

@JonB When wrapping a function with a decorator, the new (wrapper) function's arguments are normally declared as (*args, **kwargs). I'm not sure if functools.wraps fixes (or can even fix) this. Maybe the issue is really with create_objc_class not understanding varargs.

omz

If the method will be called on the main thread anyway, there's no need to decorate it with on_main_thread.