1
:mod:`pyclbr` --- Python class browser support
2
==============================================
5
:synopsis: Supports information extraction for a Python class browser.
6
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
8
**Source code:** :source:`Lib/pyclbr.py`
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
22
.. function:: readmodule(module, path=None)
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.
31
.. function:: readmodule_ex(module, path=None)
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
41
.. _pyclbr-class-objects:
46
The :class:`Class` objects used as values in the dictionary returned by
47
:func:`readmodule` and :func:`readmodule_ex` provide the following data
51
.. attribute:: Class.module
53
The name of the module defining the class described by the class descriptor.
56
.. attribute:: Class.name
58
The name of the class.
61
.. attribute:: Class.super
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`
70
.. attribute:: Class.methods
72
A dictionary mapping method names to line numbers.
75
.. attribute:: Class.file
77
Name of the file containing the ``class`` statement defining the class.
80
.. attribute:: Class.lineno
82
The line number of the ``class`` statement within the file named by
86
.. _pyclbr-function-objects:
91
The :class:`Function` objects used as values in the dictionary returned by
92
:func:`readmodule_ex` provide the following attributes:
95
.. attribute:: Function.module
97
The name of the module defining the function described by the function
101
.. attribute:: Function.name
103
The name of the function.
106
.. attribute:: Function.file
108
Name of the file containing the ``def`` statement defining the function.
111
.. attribute:: Function.lineno
113
The line number of the ``def`` statement within the file named by
114
:attr:`~Function.file`.