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.

Yesterday I found the last piece of the puzzle. Aha!  *g.funcToMethod* (a 
thin wrapper for setattr) can be applied to *classes*, not just class 
*instances!* 

This Aha changes everything! There is no need to create a plugin framework 
for pyflakes! Checker.__init__ doesn't need to change! Here's my latest 
experimental (Leonine!) script:

import ast
from pyflakes.api import check
from pyflakes.checker import Checker
<< define test >>
# Define an ATTRIBUTE *function*,
# to be converted to a Checker *method*.
@others 
g.funcToMethod(ATTRIBUTE, Checker)
check(test, filename='pyflakes_test.py')

Any changes to the ATTRIBUTE function take effect immediately, without 
calling importlib.reload. That's big. I live for these Ahas. 

Edward

P.S. Here is the latest version of the ATTRIBUTE function. 

def ATTRIBUTE(self, node) -> None:
    if isinstance(node.value, ast.Name):
        g.trace(
            f"{node.ctx.__class__.__name__}"
            f"{node.value.id}.{node.attr}")
    self.handleChildren(node)

It replaces (part of) this assignment in checker.py:

# "expr" type nodes
BOOLOP = UNARYOP = SET = ATTRIBUTE = STARRED = NAMECONSTANT = \
    NAMEDEXPR = handleChildren

EKR

-- 
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/0ee10516-726a-42d8-a7b1-4914a0e533e7n%40googlegroups.com.

Reply via email to