When I developed the modification of the code that draws the right margin guide, I didn't have to actually change any code in LeoPyRef.leo, where all of Leo's code resides. Instead, I copied the existing code from LeoPyRef to a node in my workbook.leo outline. I monkeypatched that node. This way, I could run my changed code with CNTL-b, and have the change take effect right then without reloading or rebooting.
Here's how I did the monkeypatch. I needed to modify the paint callback code for the body editor. I copied the code (I'm not showing the imports and constant declarations I had to include to make it work):
def newpaintEvent(self, event: QPaintEvent) -> None:
"""This is the code I changed."""
.... # this is the last line of the changed callback.
# this line installs the monkeypatch
LeoQTextBrowser.paintEvent = newpaintEvent
Executing this node installs the monkey patch. The next time the paintEvent fires, the new code executes. You can keep on modifying the code and re-executing until it works the way you want.
It is a good idea to run the code in a second instance of Leo, in case something goes badly wrong. But whether you do or not, on Leo's next restart, the monkey patch will be gone until you execute it again.
Once the code is correct you can copy it into LeoPyRef (without the monkeypatch), and make a final test.
I have used this technique for several projects that change code code. It's very convenient.