robertklep / quotefixformac

QuoteFix for Apple Mail —
https://github.com/robertklep/quotefixformac/releases/latest
191 stars 15 forks source link

BadPrototypeError #75

Open ryanphuang opened 7 years ago

ryanphuang commented 7 years ago

I encountered a BadPrototypeError when using the plugin.

Jan  1 16:44:06 MacBook-Pro-8 Mail[26372]: QuoteFix has encountered a fatal error, and will now terminate.
Jan  1 16:44:06 MacBook-Pro-8 Mail[26372]: An uncaught exception was raised during execution of the main script:

    BadPrototypeError: Objective-C expects 1 arguments, Python argument has 2 arguments for <unbound selector set_state_and_title of Menu at 0x11459f1d0>

It looks it's because I installed a new version of pyobjc, which enforces more strictly on the selector mapping: https://pythonhosted.org/pyobjc/core/changelog.html

If these methods are only used from Python and are never used from Objective-C the error can be avoided by decorating these methods with objc.python_method:

class MyObject (NSObject): @objc.python_method def mymethod(self, a, b): ...

I added this into the quotefix/menu.py methods, but then it failed with

ImportError: cannot import name MessageHeaders

robertklep commented 7 years ago

Thanks for the heads-up.

Did you get that error just by installing a new version of PyObjC, or did you also build the plugin using that version? I build the QF plugin using specific version of Python (and PyObjC) and I honestly thought that the plugin was self-contained (i.e. it shouldn't be influenced by globally installed Python/PyObjC).

ryanphuang commented 7 years ago

I initially got the error by just just directly using the released .mailbundle. If I uninstall the new version (3.2.1) pyobjc, the errors will be gone. So I thought it has dependency on system-wide pyobjc. But then I realize, there was another .mailbundle plugin in my Mails/Bundles that is compiled with the new version pyobjc. If I remove that .mailbundle, even if I have a 3.2.1 pyobjc installed, the release version QF will without problem.

So in short, you are right, the plugin was self-contained, as long as no other plugins that are compiled with the new pyobjc, QF works for me, but if there's another new plugin or I want to build QF by myself, the errors still exist.

robertklep commented 7 years ago

Oh, yeah, that could very well cause issues, because AFAIK only one version of the framework can be active inside the Mail app at any one time (and it's a bit of a gamble which one gets loaded first).

My guess is that after decorating the set_state_and_title method, you just hit the next backward incompatible error :(

At some point I'll try and see if I can install the new PyObjC in such a way that it won't break my current setup (which is a bit fragile, I have to admit).