# `pyclbr` --- Python 模块浏览器支持

源代码: Lib/pyclbr.py

`pyclbr` 模块提供了对于以 Python 编写的模块中定义的函数、类和方法的受限信息。 这种信息足够用来实现一个模块浏览器。 这种信息是从 Python 源代码中直接提取而非通过导入模块，因此该模块可以安全地用于不受信任的代码。 此限制使得非 Python 实现的模块无法使用此模块，包括所有标准和可选的扩展模块。

`pyclbr.``readmodule`(module, path=None)

  Return a dictionary mapping module-level class names to class descriptors. If possible, descriptors for imported base classes are included. Parameter module is a string with the name of the module to read; it may be the name of a module within a package. If given, path is a sequence of directory paths prepended to `sys.path`, which is used to locate the module source code.

  This function is the original interface and is only kept for back compatibility. It returns a filtered version of the following.

`pyclbr.``readmodule_ex`(module, path=None)

  Return a dictionary-based tree containing a function or class descriptors for each function and class defined in the module with a `def` or `class` statement. The returned dictionary maps module-level function and class names to their descriptors. Nested objects are entered into the children dictionary of their parent. As with readmodule, module names the module to be read and path is prepended to sys.path. If the module being read is a package, the returned dictionary has a key `'__path__'` whose value is a list containing the package search path.

3.7 版新加入: Descriptors for nested definitions. They are accessed through the new children attribute. Each has a new parent attribute.

The descriptors returned by these functions are instances of Function and Class classes. Users are not expected to create instances of these classes.

## 函式物件

Class `Function` instances describe functions defined by def statements. They have the following attributes:

`Function.``file`

  Name of the file in which the function is defined.

`Function.``module`

  The name of the module defining the function described.

`Function.``name`

  The name of the function.

`Function.``lineno`

  The line number in the file where the definition starts.

`Function.``parent`

  For top-level functions, None. For nested functions, the parent.

  3.7 版新加入.

`Function.``children`

  A dictionary mapping names to descriptors for nested functions and classes.

  3.7 版新加入.

## 类对象

Class `Class` instances describe classes defined by class statements. They have the same attributes as Functions and two more.

`Class.``file`

  Name of the file in which the class is defined.

`Class.``module`

  The name of the module defining the class described.

`Class.``name`

  The name of the class.

`Class.``lineno`

  The line number in the file where the definition starts.

`Class.``parent`

  For top-level classes, None. For nested classes, the parent.

  3.7 版新加入.

`Class.``children`

  A dictionary mapping names to descriptors for nested functions and classes.

  3.7 版新加入.

`Class.``super`

  A list of `Class` objects which describe the immediate base classes of the class being described. Classes which are named as superclasses but which are not discoverable by `readmodule_ex()` are listed as a string with the class name instead of as `Class` objects.

`Class.``methods`

  A dictionary mapping method names to line numbers. This can be derived from the newer children dictionary, but remains for back-compatibility.