An Empirical Study of Type-Related Defects in Python']Python Projects

被引:6
|
作者
Khan, Faizan [1 ]
Chen, Boqi [1 ]
Varro, Daniel [1 ]
McIntosh, Shane [2 ]
机构
[1] McGill Univ, Dept Elect & Comp Engn, Montreal, PQ H3A 0G4, Canada
[2] Univ Waterloo, David R Cheriton Sch Comp Sci, Waterloo, ON N2L 3G1, Canada
关键词
!text type='Python']Python[!/text; Annotations; Tools; Task analysis; Ecosystems; Software systems; Software measurement; Software defects; static type checkers; dynamic type systems; empirical study; DYNAMIC TYPE SYSTEMS;
D O I
10.1109/TSE.2021.3082068
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
In recent years, Python has experienced an explosive growth in adoption, particularly among open source projects. While Python's dynamically-typed nature provides developers with powerful programming abstractions, that same dynamic type system allows for type-related defects to accumulate in code bases. To aid in the early detection of type-related defects, type annotations were introduced into the Python ecosystem (i.e., PEP-484) and static type checkers like mypy have appeared on the market. While applying a type checker like mypy can in theory help to catch type-related defects before they impact users, little is known about the real impact of adopting a type checker to reveal defects in Python projects. In this paper, we study the extent to which Python projects benefit from such type checking features. For this purpose, we mine the issue tracking and version control repositories of 210 Python projects on GitHub. Inspired by the work of Gao et al. on type-related defects in JavaScript, we add type annotations to test whether mypy detects an error that would have helped developers to avoid real defects. We observe that 15 percent of the defects could have been prevented by mypy. Moreover, we find that there is no significant difference between the experience level of developers committing type-related defects and the experience of developers committing defects that are not type-related. In addition, a manual analysis of the anti-patterns that most commonly lead to type-checking faults reveals that the redefinition of Python references, dynamic attribute initialization and incorrectly handled Null objects are the most common causes of type-related faults. Since our study is conducted on fixed public defects that have gone through code reviews and multiple test cycles, these results represent a lower bound on the benefits of adopting a type checker. Therefore, we recommend incorporating a static type checker like mypy into the development workflow, as not only will it prevent type-related defects but also mitigate certain anti-patterns during development.
引用
收藏
页码:3145 / 3158
页数:14
相关论文
共 50 条
  • [1] An Empirical Study of Dynamic Types for Python']Python Projects
    Xia, Xinmeng
    He, Xincheng
    Yan, Yanyan
    Xu, Lei
    Xu, Baowen
    [J]. SOFTWARE ANALYSIS, TESTING, AND EVOLUTION, SATE 2018, 2018, 11293 : 85 - 100
  • [2] An Empirical Study for Common Language Features Used in Python']Python Projects
    Peng, Yun
    Zhang, Yu
    Hu, Mingzhe
    [J]. 2021 IEEE INTERNATIONAL CONFERENCE ON SOFTWARE ANALYSIS, EVOLUTION AND REENGINEERING (SANER 2021), 2021, : 24 - 35
  • [3] The Evolution of Type Annotations in Python']Python: An Empirical Study
    Di Grazia, Luca
    Pradel, Michael
    [J]. PROCEEDINGS OF THE 30TH ACM JOINT MEETING EUROPEAN SOFTWARE ENGINEERING CONFERENCE AND SYMPOSIUM ON THE FOUNDATIONS OF SOFTWARE ENGINEERING, ESEC/FSE 2022, 2022, : 209 - 220
  • [4] Risky Dynamic Typing-related Practices in Python']Python: An Empirical StudyRisky Dynamic Typing-related Practices in Python']Python: An Empirical Study
    Chen, Zhifei
    Chen, Lin
    Yang, Yibiao
    Feng, Qiong
    Li, Xuansong
    Song, Wei
    [J]. ACM TRANSACTIONS ON SOFTWARE ENGINEERING AND METHODOLOGY, 2024, 33 (06)
  • [5] An Empirical Study on Dynamic Typing Related Practices in Python']Python Systems
    Chen, Zhifei
    Li, Yanhui
    Chen, Bihuan
    Ma, Wanwangying
    Chen, Lin
    Xu, Baowen
    [J]. 2020 IEEE/ACM 28TH INTERNATIONAL CONFERENCE ON PROGRAM COMPREHENSION, ICPC, 2020, : 83 - 93
  • [6] A Large-Scale Study of ML-Related Python']Python Projects
    Idowu, Samuel
    Sens, Yorick
    Berger, Thorsten
    Kruger, Jacob
    Vierhauser, Michael
    [J]. 39TH ANNUAL ACM SYMPOSIUM ON APPLIED COMPUTING, SAC 2024, 2024, : 1272 - 1281
  • [7] Are there any Unit Tests? An Empirical Study on Unit Testing in Open Source Python']Python Projects
    Trautsch, Fabian
    Grabowski, Jens
    [J]. 2017 10TH IEEE INTERNATIONAL CONFERENCE ON SOFTWARE TESTING, VERIFICATION AND VALIDATION (ICST), 2017, : 207 - 218
  • [8] Empirical Study of Python']Python Call Graph
    Li, Yu
    [J]. 34TH IEEE/ACM INTERNATIONAL CONFERENCE ON AUTOMATED SOFTWARE ENGINEERING (ASE 2019), 2019, : 1274 - 1276
  • [9] Study of defects in a program code in Python']Python
    Bronshteyn, I. E.
    [J]. PROGRAMMING AND COMPUTER SOFTWARE, 2013, 39 (06) : 279 - 284
  • [10] Towards a Large -Scale Empirical Study of Python']Python Static Type Annotations
    Lin, Xinrong
    Hua, Baojian
    Wang, Yang
    Pan, Zhizhong
    [J]. 2023 IEEE INTERNATIONAL CONFERENCE ON SOFTWARE ANALYSIS, EVOLUTION AND REENGINEERING, SANER, 2023, : 414 - 425