Page 29 - 《软件学报》2025年第4期
P. 29
软件学报 ISSN 1000-9825, CODEN RUXUEW E-mail: jos@iscas.ac.cn
2025,36(4):1435−1460 [doi: 10.13328/j.cnki.jos.007224] [CSTR: 32375.14.jos.007224] http://www.jos.org.cn
©中国科学院软件研究所版权所有. Tel: +86-10-62562563
*
基于静态分析的 Python 第三方库 API 兼容性问题检测方法
沈 阚, 黄凯锋, 陈碧欢, 彭 鑫
(复旦大学 计算机科学技术学院, 上海 200433)
通信作者: 黄凯锋, E-mail: kaifenghuang@fudan.edu.cn
摘 要: Python 丰富的开发生态提供了多种多样的第三方库, 极大地提高了开发者的开发效率和质量. 第三方库开
发者通过对代码底层的封装, 使得上层应用开发者只需调用 API 就可以使用相关功能, 从而快速完成开发任务. 然
而, 第三方库 API 不会保持恒定不变. 由于缺陷修复、代码重构、功能新增等, 第三方库代码会不断更新. 更新后
部分 API 发生了不兼容的更改, 从而导致上层应用运行异常终止或者产生不一致的结果. 因此, Python 第三方库
API 的兼容性问题已成为目前开源生态中亟需解决的问题之一. 目前已有相关研究工作对 Python 第三方库 API 兼
容性问题展开研究, 但兼容性问题原因的分类覆盖不够完全, 无法输出兼容性问题的细粒度原因. 为此, 对 Python
第三方库 API 兼容性问题的表现形式和产生原因开展了实证研究, 并针对性提出了 Python 不兼容 API 的静态检
测方法. 首先, 针对 flask 库和 pandas 库的总共 6 个版本对, 通过收集版本更新日志、运行回归测试相结合的方法,
共收集 108 个不兼容 API 对. 接着, 对收集到的数据开展实证研究, 总结了 Python 第三方库 API 兼容性问题的表
现形式和产生原因. 最后, 提出了一种基于静态分析技术的 Python 不兼容 API 的检测方法, 输出句法层面的不兼
容 API 问题产生原因. 在 4 个常用 Python 第三方库的共计 12 个版本对上进行了实验评估, 结果表明检测方法具
有良好的有效性、泛化性、时间性能、空间性能以及易用性.
关键词: Python; 静态分析; 第三方库; API 兼容性问题; 版本演化
中图法分类号: TP311
中文引用格式: 沈阚, 黄凯锋, 陈碧欢, 彭鑫. 基于静态分析的Python第三方库API兼容性问题检测方法. 软件学报, 2025, 36(4):
1435–1460. http://www.jos.org.cn/1000-9825/7224.htm
英文引用格式: Shen K, Huang KF, Chen BH, Peng X. Detecting Incompatible Third-party Library APIs in Python Based on Static
Analysis. Ruan Jian Xue Bao/Journal of Software, 2025, 36(4): 1435–1460 (in Chinese). http://www.jos.org.cn/1000-9825/7224.htm
Detecting Incompatible Third-party Library APIs in Python Based on Static Analysis
SHEN Kan, HUANG Kai-Feng, CHEN Bi-Huan, PENG Xin
(School of Computer Science, Fudan University, Shanghai 200433, China)
Abstract: The rich development ecosystem of Python provides a lot of third-party libraries, significantly boosting developers’ efficiency
and quality. Third-party library developers encapsulate underlying code, enabling upper-layer application developers to swiftly accomplish
tasks by calling relevant APIs. However, APIs of third-party libraries are not constant. Owing to fixes, refactoring and feature additions,
these libraries undergo continuous updates. Incompatible changes are seen in some APIs after updates, leading to abnormal termination or
inconsistent results in upper-layer applications. Therefore, the API compatibility of the Python third-party library has become one of the
issues that needs to be solved. There have been related studies focusing on API compatibility issues of Python third-party libraries, of
which reasons have yet to be fully classified so that, the fine-grained cause can not be provided. An empirical study is conducted on the
symptoms and causes of API compatibility issues with Python third-party library and a targeted static detection method is proposed.
Initially, this study gathers 108 pairs of incompatible API versions by combining version update logs and regression tests across 6 version
* 基金项目: 国家自然科学基金 (62372114); 中国博士后科学基金 (2022M720768)
收稿时间: 2023-12-18; 修改时间: 2024-03-20, 2024-05-06; 采用时间: 2024-05-14; jos 在线出版时间: 2024-07-03
CNKI 网络首发时间: 2024-07-05