Fred Drake | 6b103f1 | 1999-02-18 21:06:50 +0000 | [diff] [blame] | 1 | \section{\module{pyclbr} --- |
Fred Drake | 7ceb577 | 1999-04-20 18:18:53 +0000 | [diff] [blame] | 2 | Python class browser support} |
Fred Drake | 6b103f1 | 1999-02-18 21:06:50 +0000 | [diff] [blame] | 3 | |
| 4 | \declaremodule{standard}{pyclbr} |
| 5 | \modulesynopsis{Supports information extraction for a Python class |
Fred Drake | 7ceb577 | 1999-04-20 18:18:53 +0000 | [diff] [blame] | 6 | browser.} |
Fred Drake | 6b103f1 | 1999-02-18 21:06:50 +0000 | [diff] [blame] | 7 | \sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org} |
| 8 | |
| 9 | |
| 10 | The \module{pyclbr} can be used to determine some limited information |
Alex Martelli | 37dc334 | 2003-11-09 16:32:54 +0000 | [diff] [blame] | 11 | about the classes, methods and top-level functions |
| 12 | defined in a module. The information |
Fred Drake | 6b103f1 | 1999-02-18 21:06:50 +0000 | [diff] [blame] | 13 | provided is sufficient to implement a traditional three-pane class |
| 14 | browser. The information is extracted from the source code rather |
Alex Martelli | 37dc334 | 2003-11-09 16:32:54 +0000 | [diff] [blame] | 15 | than by importing the module, so this module is safe to use with |
Fred Drake | ef1a029 | 1999-06-29 15:43:02 +0000 | [diff] [blame] | 16 | untrusted source code. This restriction makes it impossible to use |
| 17 | this module with modules not implemented in Python, including many |
| 18 | standard and optional extension modules. |
Fred Drake | 6b103f1 | 1999-02-18 21:06:50 +0000 | [diff] [blame] | 19 | |
| 20 | |
| 21 | \begin{funcdesc}{readmodule}{module\optional{, path}} |
| 22 | % The 'inpackage' parameter appears to be for internal use only.... |
| 23 | Read a module and return a dictionary mapping class names to class |
| 24 | descriptor objects. The parameter \var{module} should be the name |
| 25 | of a module as a string; it may be the name of a module within a |
| 26 | package. The \var{path} parameter should be a sequence, and is used |
| 27 | to augment the value of \code{sys.path}, which is used to locate |
| 28 | module source code. |
| 29 | \end{funcdesc} |
| 30 | |
Alex Martelli | 37dc334 | 2003-11-09 16:32:54 +0000 | [diff] [blame] | 31 | \begin{funcdesc}{readmodule_ex}{module\optional{, path}} |
| 32 | % The 'inpackage' parameter appears to be for internal use only.... |
| 33 | Like \function{readmodule()}, but the returned dictionary, in addition |
| 34 | to mapping class names to class descriptor objects, also maps |
| 35 | top-level function names to function descriptor objects. Moreover, if |
| 36 | the module being read is a package, the key \code{'__path__'} in the |
| 37 | returned dictionary has as its value a list which contains the package |
| 38 | search path. |
| 39 | \end{funcdesc} |
| 40 | |
Fred Drake | 6b103f1 | 1999-02-18 21:06:50 +0000 | [diff] [blame] | 41 | |
| 42 | \subsection{Class Descriptor Objects \label{pyclbr-class-objects}} |
| 43 | |
| 44 | The class descriptor objects used as values in the dictionary returned |
Alex Martelli | 37dc334 | 2003-11-09 16:32:54 +0000 | [diff] [blame] | 45 | by \function{readmodule()} and \function{readmodule_ex()} |
| 46 | provide the following data members: |
Fred Drake | 6b103f1 | 1999-02-18 21:06:50 +0000 | [diff] [blame] | 47 | |
| 48 | |
Fred Drake | 7ceb577 | 1999-04-20 18:18:53 +0000 | [diff] [blame] | 49 | \begin{memberdesc}[class descriptor]{module} |
| 50 | The name of the module defining the class described by the class |
| 51 | descriptor. |
| 52 | \end{memberdesc} |
| 53 | |
Fred Drake | 6b103f1 | 1999-02-18 21:06:50 +0000 | [diff] [blame] | 54 | \begin{memberdesc}[class descriptor]{name} |
| 55 | The name of the class. |
| 56 | \end{memberdesc} |
| 57 | |
| 58 | \begin{memberdesc}[class descriptor]{super} |
| 59 | A list of class descriptors which describe the immediate base |
| 60 | classes of the class being described. Classes which are named as |
| 61 | superclasses but which are not discoverable by |
| 62 | \function{readmodule()} are listed as a string with the class name |
| 63 | instead of class descriptors. |
| 64 | \end{memberdesc} |
| 65 | |
| 66 | \begin{memberdesc}[class descriptor]{methods} |
| 67 | A dictionary mapping method names to line numbers. |
| 68 | \end{memberdesc} |
| 69 | |
| 70 | \begin{memberdesc}[class descriptor]{file} |
Fred Drake | d85ed1b | 2003-11-10 14:50:54 +0000 | [diff] [blame^] | 71 | Name of the file containing the \code{class} statement defining the class. |
Fred Drake | 6b103f1 | 1999-02-18 21:06:50 +0000 | [diff] [blame] | 72 | \end{memberdesc} |
| 73 | |
| 74 | \begin{memberdesc}[class descriptor]{lineno} |
Alex Martelli | 37dc334 | 2003-11-09 16:32:54 +0000 | [diff] [blame] | 75 | The line number of the \code{class} statement within the file named by |
Fred Drake | 6b103f1 | 1999-02-18 21:06:50 +0000 | [diff] [blame] | 76 | \member{file}. |
| 77 | \end{memberdesc} |
Alex Martelli | 37dc334 | 2003-11-09 16:32:54 +0000 | [diff] [blame] | 78 | |
| 79 | \subsection{Function Descriptor Objects \label{pyclbr-function-objects}} |
| 80 | |
| 81 | The function descriptor objects used as values in the dictionary returned |
| 82 | by \function{readmodule_ex()} provide the following data members: |
| 83 | |
| 84 | |
| 85 | \begin{memberdesc}[function descriptor]{module} |
| 86 | The name of the module defining the function described by the function |
| 87 | descriptor. |
| 88 | \end{memberdesc} |
| 89 | |
| 90 | \begin{memberdesc}[function descriptor]{name} |
| 91 | The name of the function. |
| 92 | \end{memberdesc} |
| 93 | |
| 94 | \begin{memberdesc}[function descriptor]{file} |
| 95 | Name of the file containing the \code{def} statement defining the function. |
| 96 | \end{memberdesc} |
| 97 | |
| 98 | \begin{memberdesc}[function descriptor]{lineno} |
| 99 | The line number of the \code{def} statement within the file named by |
| 100 | \member{file}. |
| 101 | \end{memberdesc} |
| 102 | |