How Well Static Type Checkers Work with Gradual Typing? A Case Study on Python']Python

被引:1
作者
Xu, Wenjie [1 ,2 ]
Chen, Lin [1 ,2 ]
Su, Chenghao [1 ,2 ]
Guo, Yimeng [1 ,2 ]
Li, Yanhui [1 ,2 ]
Zhou, Yuming [1 ,2 ]
Xu, Baowen [1 ,2 ]
机构
[1] Nanjing Univ, State Key Lab Novel Software Technol, Nanjing, Peoples R China
[2] Nanjing Univ, Dept Comp Sci & Technol, Nanjing, Peoples R China
来源
2023 IEEE/ACM 31ST INTERNATIONAL CONFERENCE ON PROGRAM COMPREHENSION, ICPC | 2023年
关键词
bug detection; type annotation; !text type='Python']Python[!/text; gradual typing; static type checking; SYSTEMS;
D O I
10.1109/ICPC58990.2023.00039
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Python has become increasingly popular and widely used in many fields. Dynamic features of Python provide much convenience for developers. However, they can also cause many type-related bugs undetected until runtime, which increases the cost of maintenance. Static type checking is essential to find bugs early, and the introduction of gradual typing and type annotations makes it easier to perform static type analysis. However, it remains to be investigated how well gradual typing improves real bug detection. Therefore, we conducted a comprehensive study on three widely used checkers: MyPy, PyRight, and PyType. We used a benchmark containing 10 popular Python projects with 40 real type-related bugs. First, we performed static type checking on the projects with and without type annotations to evaluate the effectiveness of finding real bugs. Second, we manually analyzed the missing bugs and investigated the reasons. The results show that the three tools can detect 29 of the 40 studied bugs after annotating, while only 14 bugs are detected before annotating. We also found that type annotations can substantially improve the ability of static type checkers to detect real bugs. A detailed analysis of bugs missed by the checkers shows that: (i) the accuracy of type analysis is challenged when it comes to programs with complicated dynamic features, such as dynamically changing object's attributes, even with annotations; (ii) the inaccurate type annotations can undermine the ability of static type checkers to detect real bugs; (iii) static type checkers have different checking strategies in some cases, which has an impact on real bug detection. Our study can not only enable developers to better understand static type checking and make better use of them but also guide future research.
引用
收藏
页码:242 / 253
页数:12
相关论文
共 50 条
[1]  
Abdelaziz Ibrahim., 2022, Large scale generation of labeled type data for python
[2]   TYPILUS: Neural Type Hints [J].
Allamanis, Miltiadis ;
Barr, Earl T. ;
Ducousso, Soline ;
Gao, Zheng .
PROCEEDINGS OF THE 41ST ACM SIGPLAN CONFERENCE ON PROGRAMMING LANGUAGE DESIGN AND IMPLEMENTATION (PLDI '20), 2020, :91-105
[3]  
Cousot P., 1977, PROC POPL 77, DOI DOI 10.1145/512950.512973
[4]  
dropbox, 2017, Pyannotate: Auto-generate PEP-484 annotations
[5]   Static Value Analysis of Python']Python Programs by Abstract Interpretation [J].
Fromherz, Aymeric ;
Ouadjaout, Abdelraouf ;
Mine, Antoine .
NASA FORMAL METHODS, NFM 2018, 2018, 10811 :185-202
[6]   To Type or Not to Type: Quantifying Detectable Bugs in Java']JavaScript [J].
Gao, Zheng ;
Bird, Christian ;
Barr, Earl T. .
2017 IEEE/ACM 39TH INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING (ICSE), 2017, :758-769
[7]  
github.com, MYPY OPTIONAL STATIC
[8]  
github.com, PYRIGHT STATIC TYPE
[9]  
github.com, PYTYPE STATIC TYPE A
[10]  
Gong L, 2015, P 2015 INT S SOFTW T, P94, DOI 10.1145/2771783.2771809