On Sun, 6 Jul 2014 02:04:11 -0700 (PDT)
Fidel N <
fidel...@gmail.com> wrote:
> Is there a way I could still import files that way, without having to
> touch LeoPyRef?
> Having that file uncompatible with the main Leo repo keeps me away
> from making pull requests and such, since whenever I want to suggest
> something, that line gets in the way. And I cant update Leo quickly
> because then I have to edit that line again, etc.
In similar cases I've used a @script node in my local (personal,
i.e. not part of Leo) .leo files to alter Leo's behavior via monkey
patching.
Hmm, this example turned out less interesting than I thought:
class LeoInternalClass:
def seven(self, x):
print(7,x)
lic1 = LeoInternalClass()
lic2 = LeoInternalClass()
print("pre-patch")
lic1.seven('1')
lic2.seven('2')
def new_seven(self,x):
print("seven",x)
LeoInternalClass.seven = new_seven
print("\nPatch class and lic2 instance")
lic2.seven = lambda x, self=lic2: new_seven(self, x)
lic3 = LeoInternalClass()
lic1.seven('1')
lic2.seven('2')
lic3.seven('3')
def newer_seven(self,x):
print("3+4",x)
LeoInternalClass.seven = newer_seven
lic4 = LeoInternalClass()
print("\nPatch class again")
lic1.seven('1')
lic2.seven('2')
lic3.seven('3')
lic4.seven('4')
Basically, patch the class, all current and future instances affected
*unless* the instance has been patched. Patch the instance, and
patches to the class are irrelevant.
Cheers -Terry