Very cool to monkeypatch a class. It makes sense - good old Python! I don't 
remember if I ever patched a class but I have monkeypatched module 
variables.  I remember that I developed Leo's highlighting of the current 
line and the right margin guideline mostly by monkeypatching instances 
using scripts in my workbook.  Some of the functionality of my GF4 Graphic 
Calculator application is provided by what is in effect monkeypatching 
additional commands into the dispatching class. That is done by importing 
the modules inside the class definition so that their "self" parameter when 
called will be the class instance. 

On Thursday, November 27, 2025 at 9:13:45 AM UTC-5 Edward K. Ream wrote:

> On Thursday, November 27, 2025 at 5:20:15 AM UTC-6 Edward K. Ream wrote:
>
> > Working directly in site-packages/pyflakes is turning out to be an 
> excellent (if eccentric) strategy.  It's liberating to use live code 
> without cloning or forking a repo.
>
> I've created the ekr-live-pyflakes repo <http://ekr-live-pyflakes> for 
> this work. As stated in the readme, this repo will be my private playground 
> for the foreseeable future.
>
> > Any changes to the ATTRIBUTE function take effect immediately, without 
> calling importlib.reload 
>
> Note that non-patched changes take effect only after reloading Leo (or 
> after importlib.reload). So far, the only such change is pylint.__init__.py:
>
> # True only when running the test-pyflakes script.
> trace = False
>
> My test script now contains:
>
> try:
>     pyflakes.trace = True
>     check(test, filename='pyflakes_test.py')
> finally:
>     pyflakes.trace = False
>
> The patched ATTRIBUTE function is now:
>
> def ATTRIBUTE(self, node) -> None:
>     if isinstance(node.value, ast.Name):
>         if pyflakes.trace:
>
>             g.trace(
>                 f"{node.ctx.__class__.__name__}"
>                 f"{node.value.id}.{node.attr}"
>             )
>     self.handleChildren(node)
>
>
> *Summary*
>
> This is a supremely light and flexible framework:
>
> - I expect all experiments will occur in patched code. They have no effect 
> on production code such as my pyflakes-leo.cmd script.
> - I back up all code with a push from Python's site-packages/pyflakes 
> directory.
> - Nothing I do will have any effect on pyflakes itself. I can create my 
> own issues in my repo.
>
> This is the workflow of my dreams. Onward to the study and improvement of 
> pyflakes!
>
> Edward
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/leo-editor/d0312d1e-65f7-4888-9172-0694e132b2b7n%40googlegroups.com.

Reply via email to