In modern software development, Python third-party libraries play a critical role, especially in fields like deep learning and scientific computing. However, API parameters in these libraries often change during evolution, leading to compatibility issues for client applications reliant on specific versions. Python's flexible parameter-passing mechanism further complicates this, as different passing methods can result in different API compatibility. Currently, no tool can automatically detect and repair Python API parameter compatibility issues. To fill this gap, we introduce PCART, the first solution to fully automate the process of API extraction, code instrumentation, API mapping establishment, compatibility assessment, repair, and validation. PCART handles various types of Python API parameter compatibility issues, including parameter addition, removal, renaming, reordering, and the conversion of positional to keyword parameters. To evaluate PCART, we construct PCBENCH, a large-scale benchmark comprising 47,478 test cases mutated from 844 parameter-changed APIs across 33 popular Python libraries. Evaluation results demonstrate that PCART is both effective and efficient, significantly outperforming existing tools (MLCatchUp and Relancer) and the large language model ChatGPT (GPT-4o), achieving an F1-score of 96.51% in detecting API parameter compatibility issues and a repair precision of 91.97%. Further evaluation on 30 real-world Python projects from GitHub confirms PCART's practicality. We believe PCART can significantly reduce the time programmers spend maintaining Python API updates and advance the automation of Python API compatibility issue repair.
翻译:在现代软件开发中,Python第三方库发挥着至关重要的作用,尤其是在深度学习和科学计算等领域。然而,这些库中的API参数在演化过程中经常发生变化,导致依赖特定版本的客户端应用程序出现兼容性问题。Python灵活的传参机制进一步加剧了这一问题,因为不同的参数传递方式可能导致不同的API兼容性。目前,尚无工具能够自动检测并修复Python API参数兼容性问题。为填补这一空白,我们提出了PCART,这是首个实现API提取、代码插桩、API映射建立、兼容性评估、修复及验证全流程自动化的解决方案。PCART能够处理多种类型的Python API参数兼容性问题,包括参数增加、删除、重命名、重新排序以及位置参数向关键字参数的转换。为评估PCART,我们构建了PCBENCH大规模基准测试集,包含从33个流行Python库的844个参数变更API变异生成的47,478个测试用例。评估结果表明,PCART在检测API参数兼容性问题方面取得了96.51%的F1分数,修复精度达到91.97%,在效果和效率上均显著优于现有工具(MLCatchUp和Relancer)及大语言模型ChatGPT(GPT-4o)。在GitHub上30个真实Python项目的进一步评估验证了PCART的实用性。我们相信PCART能够显著减少程序员维护Python API更新的时间,并推动Python API兼容性问题修复的自动化进程。