| 摘要: |
| 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兼容性问题 版本演化 |
| DOI:10.13328/j.cnki.jos.007224 |
| 分类号:TP311 |
| 基金项目:国家自然科学基金(62372114); 中国博士后科学基金(2022M720768) |
|
| 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 pairs of the flask and pandas libraries. Subsequently, an empirical study is conducted on the collected data, summarizing the symptoms and causes of compatibility issues. Finally, this study proposes a static analysis-based detection method for incompatible Python APIs, providing syntactic-level causes of incompatible API issues. This study conducts experimental evaluations on 12 version pairs of 4 popular Python third-party libraries. The results show that the proposed method is good in effectiveness, generalization, time performance, memory performance, and usefulness. |
| Key words: Python static analysis third-party libraries API compatibility issues version evolution |