Towards a Large-Scale Empirical Study of Python Static Type Annotations
Authors:
- 1 March 2023
- conference paper
- Published by Institute of Electrical and Electronics Engineers (IEEE)
- p. 414-425
Abstract
Python, as one of the most popular and important programming languages in the era of data science, has recently introduced a syntax for static type annotations with PEP 484, to improve code maintainability, quality, and readability. However, it is still unknown whether and how static type annotations are used in practical Python projects.This paper presents, to the best of our knowledge, the first and most comprehensive empirical study on the defects, evolution and rectification of static type annotations in Python projects. We first designed and implemented a software prototype dubbed PYSCAN, then used it to scan notable Python projects with diverse domains and sizes and type annotation manners, which add up to 19,478,428 lines of Python code. The empirical results provide interesting findings and insights, such as: 1) we proposed a taxonomy of Python type annotation-related defects, by classifying defects into four categories; 2) we investigated the evolution of type annotation-related defects; and 3) we proposed automatic defect rectification strategies, generating rectification suggestions for 82 out of 110 (74.55%) defects successfully. We suggest that: 1) Python language designers should clarify the type annotation specification; 2) checking tool builders should improve their tools to suppress false positives; and 3) Python developers should integrate such checking tools into their development workflow to catch type annotation-related defects at an early development stage.We have reported our findings and suggestions to Python language designers, checking tool builders, and Python developers. They have acknowledged us and taken actions based on our suggestions. We believe these guidelines would improve static type annotation practices and benefit the Python ecosystem in general.Keywords
Funding Information
- National Natural Science Foundation of China
This publication has 22 references indexed in Scilit:
- A large scale study of programming languages and code quality in github2014
- Type names without static type checking already improve the usability of APIs (as long as the type names are correct)2014
- An empirical study on the impact of static typing on software maintainabilityEmpirical Software Engineering, 2013
- Empirical analysis of programming language adoptionACM SIGPLAN Notices, 2013
- An experiment to test bug density in students' code (abstract only)2013
- Static vs. dynamic type systems2011
- Gradual Typing for Objects2007
- Relationships Between Selected Software Measures and Latent Bug-Density: Guidelines for Improving Quality2003
- A study of effective regression testing in practice2002
- Measuring nominal scale agreement among many raters.Psychological Bulletin, 1971