一句话:首次大规模实证研究 Python 类型注解的演化,揭示其采用模式、与类型错误的关系及开发者实践问题。
动态类型语言中的类型注解与渐进类型检查器旨在暴露错误并便于维护,但开发者采用速度、策略以及注解是否真正揭示更多类型错误尚不明确。本文对 Python 类型注解与类型错误的演化进行首次大规模实证研究,从 9,655 个项目的 1,123,393 次提交中提取 1,414,936 处类型注解变更。结果表明:(i) 类型注解日益流行,且一旦添加往往长期不变;(ii) 项目呈现三种演化模式——规律注解、type sprints 与偶发使用,且模式与贡献者数量相关;(iii) 更多注解有助于发现更多类型错误(相关性 0.704),但仍有 78.3% 的提交在存在类型错误时被提交。研究呼吁加强开发者培训、发展自动添加注解的技术,并将渐进类型检查更好地集成到开发流程中。
Type annotations and gradual type checkers attempt to reveal errors and facilitate maintenance in dynamically typed programming languages. Despite the availability of these features and tools, it is currently unclear how quickly developers are adopting them, what strategies they follow when doing so, and whether adding type annotations reveals more type errors. This paper presents the first large-scale empirical study of the evolution of type annotations and type errors in Python. The study is based on an analysis of 1,414,936 type annotation changes, which we extract from 1,123,393 commits among 9,655 projects. Our results show that (i) type annotations are getting more popular, and once added, often remain unchanged in the projects for a long time, (ii) projects follow three evolution patterns for type annotation usage -- regular annotation, type sprints, and occasional uses -- and that the used pattern correlates with the number of contributors, (iii) more type annotations help find more type errors (0.704 correlation), but nevertheless, many commits (78.3%) are committed despite having such errors. Our findings show that better developer training and automated techniques for adding type annotations are needed, as most code still remains unannotated, and they call for a better integration of gradual type checking into the development process.
DOI 原文 ·
@inproceedings{paperbot6975,
title = {The evolution of type annotations in python: an empirical study},
author = {Luca Di Grazia and Michael Pradel},
booktitle = {FSE},
year = {2022},
doi = {10.1145/3540250.3549114}
}