In modern software development, Python third-party libraries have become crucial, particularly due to their widespread use in fields such as deep learning and scientific computing. However, the parameters of APIs in third-party libraries often change during evolution, causing compatibility issues for client applications that depend on specific versions. Due to Python's flexible parameter-passing mechanism, different methods of parameter passing can result in different API compatibility. Currently, no tool is capable of automatically detecting and repairing Python API parameter compatibility issues. To fill this gap, we propose PCART, the first to implement a fully automated process from API extraction, code instrumentation, and API mapping establishment, to compatibility assessment, and finally to repair and validation, for solving various types of Python API parameter compatibility issues, i.e., parameter addition, removal, renaming, reordering of parameters, as well as the conversion of positional parameters to keyword parameters. We construct a large-scale benchmark PCBENCH, including 47,478 test cases mutated from 844 parameter-changed APIs of 33 popular Python libraries, to evaluate PCART. The evaluation results show that PCART is effective yet efficient, significantly outperforming existing tools (MLCatchUp and Relancer) and the large language model ChatGPT-4, achieving an F-measure of 96.49% in detecting API parameter compatibility issues and a repair accuracy of 91.36%. The evaluation on 14 real-world Python projects from GitHub further demonstrates that PCART has good practicality. We believe PCART can help programmers reduce the time spent on maintaining Python API updates and facilitate automated Python API compatibility issue repair.
翻译:在现代软件开发中,Python第三方库已变得至关重要,尤其是在深度学习和科学计算等领域的广泛应用。然而,第三方库中API的参数在演进过程中经常发生变化,导致依赖于特定版本的客户端应用程序出现兼容性问题。由于Python灵活的参数传递机制,不同的参数传递方式可能导致不同的API兼容性。目前,尚无工具能够自动检测和修复Python API参数兼容性问题。为填补这一空白,我们提出了PCART,它是首个实现从API提取、代码插桩、API映射建立,到兼容性评估,最终到修复与验证的全自动化流程的工具,用于解决各类Python API参数兼容性问题,即参数的增加、移除、重命名、参数顺序重排,以及位置参数到关键字参数的转换。我们构建了一个大规模基准测试集PCBENCH,包含从33个流行Python库的844个参数变更API变异而来的47,478个测试用例,用以评估PCART。评估结果表明,PCART高效且有效,显著优于现有工具(MLCatchUp和Relancer)以及大语言模型ChatGPT-4,在检测API参数兼容性问题方面达到了96.49%的F-measure,修复准确率为91.36%。在来自GitHub的14个真实Python项目上的进一步评估表明,PCART具有良好的实用性。我们相信PCART能够帮助程序员减少维护Python API更新的时间,并促进Python API兼容性问题的自动修复。