Debian Codegraph @

cpython27/Doc/library/pyclbr.rst

raw
1 :mod:`pyclbr` --- Python class browser support
2 ==============================================
3
4 .. module:: pyclbr
5 :synopsis: Supports information extraction for a Python class browser.
6 .. sectionauthor:: Fred L. Drake, Jr. <[email protected]>
7
8 **Source code:** :source:`Lib/pyclbr.py`
9
10 --------------
11
12 The :mod:`pyclbr` module can be used to determine some limited information
13 about the classes, methods and top-level functions defined in a module. The
14 information provided is sufficient to implement a traditional three-pane
15 class browser. The information is extracted from the source code rather
16 than by importing the module, so this module is safe to use with untrusted
17 code. This restriction makes it impossible to use this module with modules
18 not implemented in Python, including all standard and optional extension
19 modules.
20
21
22 .. function:: readmodule(module, path=None)
23
24 Read a module and return a dictionary mapping class names to class
25 descriptor objects. The parameter *module* should be the name of a
26 module as a string; it may be the name of a module within a package. The
27 *path* parameter should be a sequence, and is used to augment the value
28 of ``sys.path``, which is used to locate module source code.
29
30
31 .. function:: readmodule_ex(module, path=None)
32
33 Like :func:`readmodule`, but the returned dictionary, in addition to
34 mapping class names to class descriptor objects, also maps top-level
35 function names to function descriptor objects. Moreover, if the module
36 being read is a package, the key ``'__path__'`` in the returned
37 dictionary has as its value a list which contains the package search
38 path.
39
40
41 .. _pyclbr-class-objects:
42
43 Class Objects
44 -------------
45
46 The :class:`Class` objects used as values in the dictionary returned by
47 :func:`readmodule` and :func:`readmodule_ex` provide the following data
48 attributes:
49
50
51 .. attribute:: Class.module
52
53 The name of the module defining the class described by the class descriptor.
54
55
56 .. attribute:: Class.name
57
58 The name of the class.
59
60
61 .. attribute:: Class.super
62
63 A list of :class:`Class` objects which describe the immediate base
64 classes of the class being described. Classes which are named as
65 superclasses but which are not discoverable by :func:`readmodule` are
66 listed as a string with the class name instead of as :class:`Class`
67 objects.
68
69
70 .. attribute:: Class.methods
71
72 A dictionary mapping method names to line numbers.
73
74
75 .. attribute:: Class.file
76
77 Name of the file containing the ``class`` statement defining the class.
78
79
80 .. attribute:: Class.lineno
81
82 The line number of the ``class`` statement within the file named by
83 :attr:`~Class.file`.
84
85
86 .. _pyclbr-function-objects:
87
88 Function Objects
89 ----------------
90
91 The :class:`Function` objects used as values in the dictionary returned by
92 :func:`readmodule_ex` provide the following attributes:
93
94
95 .. attribute:: Function.module
96
97 The name of the module defining the function described by the function
98 descriptor.
99
100
101 .. attribute:: Function.name
102
103 The name of the function.
104
105
106 .. attribute:: Function.file
107
108 Name of the file containing the ``def`` statement defining the function.
109
110
111 .. attribute:: Function.lineno
112
113 The line number of the ``def`` statement within the file named by
114 :attr:`~Function.file`.
115