PCART  v1.4
Automated Repair of Python API Parameter Compatibility Issues
Functions
repair Namespace Reference

Repair and validate API parameter compatibility issues
More...

Functions

def findName (pos, dic)
 Find parameter name by its position 通过位置查找参数名 More...
 
def fix (callAPI, repairDict, node, starFlag, twoStarFlag)
 Perform parameter repair operations through AST 通过AST执行参数修复操作 More...
 
def mapName (name, dic)
 Get repair operation dictionary of keyword parameter 获取关键字参数的修复操作字典 More...
 
def mapPos (pos, dic)
 Get repair operation dictionary of positional parameter 获取位置参数的修复操作字典 More...
 
def mirrorAPI (fixedAPI, dic)
 Create mirror for the fixed API by adding all parameter names 给修复后API的参数填上参数名 More...
 
def repairTask (root, callAPI, apiWithValue, projName, runPath, runCommand, repairLst, virtualEnv, errLst, callKey, *runtimePaths)
 Task of repairing parameter compatibility issues 参数兼容性问题修复任务 More...
 
def validateByRun (callAPI, apiWithValue, projName, virtualEnv, runPath, runCommand, callKey, *runtimePaths)
 Dynamic validation 动态验证 More...
 
def validateByStr (fixedAPI, repairDict, targetAPIDefinition, starFlag, twoStarFlag)
 Static validation 静态验证 More...
 

Detailed Description

Repair and validate API parameter compatibility issues

Repairs API parameter compatibility issues at the AST level. Uses a two-stage validation strategy: static validation (signature check via mirrorAPI) and dynamic validation (running repaired code in targetEnv via validateByRun). The fix() function applies repair operations (delete, rename, reorder, pos↔key conversion) directly on AST nodes. 在AST层面修复API参数兼容性问题。采用两阶段验证策略:静态验证(通过mirrorAPI 进行签名检查)和动态验证(通过validateByRun在targetEnv中运行修复后代码)。 fix()函数直接在AST节点上应用修复操作(删除、重命名、重排序、位置↔关键字转换)。

Function Documentation

◆ findName()

def repair.findName (   pos,
  dic 
)

Find parameter name by its position 通过位置查找参数名

Parameters
posParameter position
dicRepair operation dictionary
Returns
key[0] The parameter name

Definition at line 68 of file repair.py.

Here is the caller graph for this function:

◆ fix()

def repair.fix (   callAPI,
  repairDict,
  node,
  starFlag,
  twoStarFlag 
)

Perform parameter repair operations through AST 通过AST执行参数修复操作

Parameters
callAPIThe API call
repairDictRepair operation dictionary
nodeThe AST node of the API call
starFlagFlag of *
twoStarFlagFlag of **

Definition at line 142 of file repair.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mapName()

def repair.mapName (   name,
  dic 
)

Get repair operation dictionary of keyword parameter 获取关键字参数的修复操作字典

Here, keyword parameter means that the parameter is passed by parameter name 此处,关键字参数指带参数名进行传递的参数

Parameters
nameParameter name
dicRepair operation dictionary
Returns
dic[key] The repair operation

Definition at line 54 of file repair.py.

Here is the caller graph for this function:

◆ mapPos()

def repair.mapPos (   pos,
  dic 
)

Get repair operation dictionary of positional parameter 获取位置参数的修复操作字典

Here, positional parameter means that the parameter is passed by position without parameter name 此处,位置参数指按位置而不带参数名进行传递的参数

Parameters
posParameter position
dicRepair operation dictionary
Returns
dic[key] The repair operation

Definition at line 34 of file repair.py.

Here is the caller graph for this function:

◆ mirrorAPI()

def repair.mirrorAPI (   fixedAPI,
  dic 
)

Create mirror for the fixed API by adding all parameter names 给修复后API的参数填上参数名

Parameters
fixedAPIFixed API
dicRepair operation dictionary
Returns
paraObjLst API mirror

Definition at line 83 of file repair.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ repairTask()

def repair.repairTask (   root,
  callAPI,
  apiWithValue,
  projName,
  runPath,
  runCommand,
  repairLst,
  virtualEnv,
  errLst,
  callKey,
runtimePaths 
)

Task of repairing parameter compatibility issues 参数兼容性问题修复任务

Checks whether apiWithValue is available. Repair success = formal fix + successful run. Returns 3 values: repair result, formal compatibility, and whether the repair succeeded. Note: after a static-only fix, the return value alone cannot distinguish dynamic success from static-only validation — an extra label is returned for this purpose. 需要判断一下apiWithValue是否为空。修复成功=形式上修复成功+成功运行。 函数返回3个值:修复结果,形式上的兼容性,是否修复成功。 修完之后无法通过返回值判断是动态修复成功还是只经过了静态验证,因此额外返回标签。

Parameters
rootThe AST root of the source file
callAPIThe API call
apiWithValueThe API call with value added by loading the pkl file
projNameThe project name
runPathThe relative path of the run file
runCommandThe run command of the project
repairLstList of repair operation dictionary
virtualEnvThe virtual environment of the target lib version
errLstList of error messages
callKeyUnique callsite artifact id
runtimePathsRuntime artifact paths for the current PCART workspace
Returns
repairResults

Definition at line 383 of file repair.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateByRun()

def repair.validateByRun (   callAPI,
  apiWithValue,
  projName,
  virtualEnv,
  runPath,
  runCommand,
  callKey,
runtimePaths 
)

Dynamic validation 动态验证

Parameters
callAPIThe API call
apiWithValueThe API call with value added by loading the pkl file
projNameThe project name
virtualEnvThe virtual environment of the target lib version
runPathThe relative path of the run file
runCommandThe run command of the project
callKeyUnique callsite artifact id
runtimePathsRuntime artifact paths for the current PCART workspace
Returns
result Dynamic validation result

Definition at line 278 of file repair.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateByStr()

def repair.validateByStr (   fixedAPI,
  repairDict,
  targetAPIDefinition,
  starFlag,
  twoStarFlag 
)

Static validation 静态验证

Parameters
fixedAPIThe fixed API
repairDictRepair operation dictionary
targetAPIDefinitionAPI definition of target lib version
starFlagFlag of *
twoStarFlagFlag of **
Returns
True/False Static validation result: passed/not passed

Definition at line 332 of file repair.py.

Here is the call graph for this function:
Here is the caller graph for this function: