pyclbr
— Python 模块浏览支持
¶
源代码: Lib/pyclbr.py
pyclbr
模块提供 python 编码模块定义的有关函数、类及方法的有限信息。这些信息足以实现模块浏览器。信息是从 Python 源代码提取的,而不是通过导入模块,因此本模块可以安全地用于不可信代码。此限定使之不可能将本模块用于未在 Python 中实现的模块,包括所有标准和可选扩展模块。
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.
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.
类
Function
instances describe functions defined by def statements. They have the following attributes:
Name of the file in which the function is defined.
描述函数定义的模块名称。
函数的名称。
The line number in the file where the definition starts.
For top-level functions, None. For nested functions, the parent.
3.7 版新增。
A dictionary mapping names to descriptors for nested functions and classes.
3.7 版新增。
True
对于定义函数具有
async
前缀,
False
否则。
3.10 版新增。
类
Class
instances describe classes defined by class statements. They have the same attributes as Functions and two more.
Name of the file in which the class is defined.
描述类定义的模块名称。
The name of the class.
The line number in the file where the definition starts.
For top-level classes, None. For nested classes, the parent.
3.7 版新增。
A dictionary mapping names to descriptors for nested functions and classes.
3.7 版新增。
列表化的
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
对象。
A dictionary mapping method names to line numbers. This can be derived from the newer children dictionary, but remains for back-compatibility.