Re: [Patches] selfnanny.py: checking for "self" in every method
On Sat, 4 Mar 2000, Guido van Rossum wrote:
Before we all start writing nannies and checkers, how about a standard API design first?
I thoroughly agree -- we should have a standard API. I tried to write selfnanny so it could be callable from any API possible (e.g., it can take either a file, a string, an ast or a tuple representation)
I will want to call various nannies from a "Check" command that I plan to add to IDLE.
Very cool: what I imagine is a sort of modular PyLint.
I already did this with tabnanny, and found that it's barely possible -- it's really written to run like a script.
Mine definitely isn't: it's designed to run both like a script and like a module. One outstanding bug: no docos. To be supplied upon request <0.5 wink>. I just wanted to float it out and see if people think that this particular nanny is worth while.
Since parsing is expensive, we probably want to share the parse tree.
Yes. Probably as an AST, and transform to tuples/lists inside the checkers.
Ideas?
Here's a strawman API:
There's a package called Nanny
Every module in that package should have a function called check_ast.
It's argument is an AST object, and it's output should be a list
of three-tuples: (line-number, error-message, None) or
(line-number, error-message, (column-begin, column-end)) (each tuple can
be a different form).
Problems?
(I'm CCing to python-dev. Please follow up to that discussion to
python-dev only, as I don't believe it belongs in patches)
--
Moshe Zadka
Guido van Rossum wrote: Before we all start writing nannies and checkers, how about a standard API design first?
Moshe Zadka wrote: Here's a strawman API: There's a package called Nanny Every module in that package should have a function called check_ast. It's argument is an AST object, and it's output should be a list of three-tuples: (line-number, error-message, None) or (line-number, error-message, (column-begin, column-end)) (each tuple can be a different form).
Greg Wilson wrote: The SUIF (Stanford University Intermediate Format) group has been working on an extensible compiler framework for about ten years now. The framework is based on an extensible AST spec; anyone can plug in a new analysis or optimization algorithm by writing one or more modules that read and write decorated ASTs. (See http://suif.stanford.edu for more information.) Based on their experience, I'd suggest that every nanny take an AST as an argument, and add complaints in place as decorations to the nodes. A terminal nanny could then collect these and display them to the user. I think this architecture will make it simpler to write meta-nannies. I'd further suggest that the AST be something that can be manipulated through DOM, since (a) it's designed for tree-crunching, (b) it's already documented reasonably well, (c) it'll save us re-inventing a wheel, and (d) generating human-readable output in a variety of customizable formats ought to be simple (well, simpler than the alternatives). Greg
participants (2)
-
gvwilson@nevex.com
-
Moshe Zadka