Monkey patching objects and classes is an option in Python3 but I'm struggling to figure out how to do it in Micropython in the absence of types.MethodType
https://filippo.io/instance-monkey-patching-in-python/
I was surprised to find with python that simply assigning a function to the Class or Object symbol table wasn't enough to bind a method. Coming from Javascript and Java and having had to put up with declaring self without having a this automatically bound, I had hoped that at least monkey-patching would be trivial, but something seems to be missing which means a function assigned as an attribute is not bound as a method.
It would help very much in development to be able to copy-paste method implementations to override the one in the module while debugging a problem, before uploading a new module with the method fixed (proven by the monkey patching).
Is this impossible in Micropython?
Monkey Patching without types.MethodType
Re: Monkey Patching without types.MethodType
You have to make the function an attribute of the class, not of the object instance, for method binding to work. It's the same as in regular Python.
Re: Monkey Patching without types.MethodType
Thanks, Deshipu. Just getting back to this after a ton of other commitments. Very useful and could have wasted a bunch of time failing to realise I was approaching it wrong.