2 :mod:`pyclbr` --- Python class browser support
3 ==============================================
6 :synopsis: Supports information extraction for a Python class browser.
7 .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
10 The :mod:`pyclbr` can be used to determine some limited information about the
11 classes, methods and top-level functions defined in a module. The information
12 provided is sufficient to implement a traditional three-pane class browser. The
13 information is extracted from the source code rather than by importing the
14 module, so this module is safe to use with untrusted source code. This
15 restriction makes it impossible to use this module with modules not implemented
16 in Python, including many standard and optional extension modules.
19 .. function:: readmodule(module[, path])
21 Read a module and return a dictionary mapping class names to class descriptor
22 objects. The parameter *module* should be the name of a module as a string;
23 it may be the name of a module within a package. The *path* parameter should
24 be a sequence, and is used to augment the value of ``sys.path``, which is
25 used to locate module source code.
27 .. The 'inpackage' parameter appears to be for internal use only....
30 .. function:: readmodule_ex(module[, path])
32 Like :func:`readmodule`, but the returned dictionary, in addition to mapping
33 class names to class descriptor objects, also maps top-level function names to
34 function descriptor objects. Moreover, if the module being read is a package,
35 the key ``'__path__'`` in the returned dictionary has as its value a list which
36 contains the package search path.
38 .. The 'inpackage' parameter appears to be for internal use only....
41 .. _pyclbr-class-objects:
43 Class Descriptor Objects
44 ------------------------
46 The class descriptor objects used as values in the dictionary returned by
47 :func:`readmodule` and :func:`readmodule_ex` provide the following data members:
50 .. attribute:: class_descriptor.module
52 The name of the module defining the class described by the class descriptor.
55 .. attribute:: class_descriptor.name
57 The name of the class.
60 .. attribute:: class_descriptor.super
62 A list of class descriptors which describe the immediate base classes of the
63 class being described. Classes which are named as superclasses but which are
64 not discoverable by :func:`readmodule` are listed as a string with the class
65 name instead of class descriptors.
68 .. attribute:: class_descriptor.methods
70 A dictionary mapping method names to line numbers.
73 .. attribute:: class_descriptor.file
75 Name of the file containing the ``class`` statement defining the class.
78 .. attribute:: class_descriptor.lineno
80 The line number of the ``class`` statement within the file named by
84 .. _pyclbr-function-objects:
86 Function Descriptor Objects
87 ---------------------------
89 The function descriptor objects used as values in the dictionary returned by
90 :func:`readmodule_ex` provide the following data members:
93 .. attribute:: function_descriptor.module
95 The name of the module defining the function described by the function
99 .. attribute:: function_descriptor.name
101 The name of the function.
104 .. attribute:: function_descriptor.file
106 Name of the file containing the ``def`` statement defining the function.
109 .. attribute:: function_descriptor.lineno
111 The line number of the ``def`` statement within the file named by :attr:`file`.