[Python-Dev] Direction of PyChecker

Guido van Rossum guido@python.org
Mon, 13 Aug 2001 09:56:51 -0400

> I think we may need to start thinking about some standard interface to byte
> code scanning.  (I keep thinking about Rattlesnake.)  Perhaps there are
> standard tasks people are performing that could be abstracted into a
> standard module (for example, getting a list of global variables that are
> set by a function, or getting first set and first read points for particular
> variables).  One complaint I saw voiced about the Rattlesnake idea was that
> code that scans byte code would break.

Code that scans bytecode is well aware that it can break.  People have
often asked me about the stability of the bytecode, and I've always
responded that it changes in every release, and is considered an
internal implementation detail.

A bytecode scanning API might be a good idea, but it might also end up
being restrictive: it's hard to design such an API without making
*some* assumptions about the general bytecode architecture, and a
future implementation might violate those assumptions.  Jython is a
case in point: it doesn't support Python's bytecode at all -- and
that's right, because it has no use for it.

For tools like PyChecker, a higher level is more appropriate: give it
an abstract syntax tree that can answer questions related to the
symbol table, so that you can tell for example whether 'x = y' assigns
a local to a global or vice versa -- and if a local is involved, in
which function it is defined.

For Rattlesnake, a bytecode accessor would of course still be needed
-- but in its capacity as an implementation detail of CPython.

--Guido van Rossum (home page: http://www.python.org/~guido/)