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__}"
It replaces (part of) this assignment in checker.py:
# "expr" type nodes
BOOLOP = UNARYOP = SET = ATTRIBUTE = STARRED = NAMECONSTANT = \
NAMEDEXPR = handleChildren
EKR