跳到主要内容

analyze_module_ast

函数源码

v_1: dict[str, tuple[int, bool]] = analyze_module_ast(module: ModuleType)

分析模块的代码结构 (AST),并返回从源码中探知到的实体信息。

参数​

输入​

参数类型必选
说明
moduleModuleType待分析的模块。

输出​

参数类型
说明
v_1dict[str, tuple[int, bool]]

name -> (lineno, is_alias)的映射。

其中, name指的是从模块探知到的实体名称。

一个“实体”可以是类、函数、变量、或是从其他模块导入的别名。例如:

  • class Foo
  • def bar
  • baz = ...
  • import x as y
  • from .sub import name
  • from external import name

lineno是实体定义在源代码中的行号。

is_alias用来标记实体是否是别名。当该值为True,这意味着实体的名字经历了导入/再导出的过程,且并非直接定义于该模块。