Table of Contents

Module: pyclbr eric3/Utilities/pyclbr.py

Parse a Python file and retrieve classes and methods.

Parse enough of a Python file to recognize class and method definitions and to find out the superclasses of a class.

The interface consists of a single function: readmodule(module, path) module is the name of a Python module, path is an optional list of directories where the module is to be searched. If present, path is prepended to the system search path sys.path. The return value is a dictionary. The keys of the dictionary are the names of the classes defined in the module (including classes that are defined via the from XXX import YYY construct). The values are class instances of the class Class defined here.

A class is described by the class Class in this module. Instances of this class have the following instance variables: name -- the name of the class super -- a list of super classes (Class instances) methods -- a dictionary of methods file -- the file in which the class was defined lineno -- the line in the file on which the class statement occurred The dictionary of methods uses the method names as keys and a tuple consisting of the line numbers on which the method was defined and a list of the methods parameters as values. If the name of a super class is not recognized, the corresponding entry in the list of super classes is not a class instance but a string giving the name of the super class. Since import statements are recognized and imported modules are scanned as well, this shouldn't happen often.

BUGS - Nested classes and functions can confuse it. - Code that doesn't pass tabnanny or python -t will confuse it, unless you set the module TABWIDTH vrbl (default 8) to the correct tab width for the file.

PACKAGE RELATED BUGS - If you have a package and a module inside that or another package with the same name, module caching doesn't work properly since the key is the base name of the module/package. - The only entry that is returned when you readmodule a package is a __path__ whose value is a list which confuses certain class browsers. - When code does: from package import subpackage class MyClass(subpackage.SuperClass): ... It can't locate the parent. It probably needs to have the same hairy logic that the import locator already does. (This logic exists coded in Python in the freeze package.)

This is a modified version of the one found in the Python 2.2.2 distribution.

Imported modules   
import imp
import re
import string
import sys
Functions   
_indent
readmodule
readmodule_ex
  _indent 
_indent ( ws,  _expandtabs=string.expandtabs )

  readmodule 
readmodule (
        module,
        path=[],
        inpackage=0,
        )

Backwards compatible interface.

Like readmodule_ex() but strips Function objects from the resulting dictionary.

  readmodule_ex 
readmodule_ex (
        module,
        path=[],
        inpackage=0,
        )

Read a module file and return a dictionary of classes.

Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module.

Classes   

Class

Class to represent a Python class.

Function

Class to represent a top-level Python function


Table of Contents

This document was automatically generated by HappyDoc version 2.1