Font Size: a A A

Python Type Annotation Analysis For Type Inferrence

Posted on:2020-02-09Degree:MasterType:Thesis
Country:ChinaCandidate:H Y MaFull Text:PDF
GTID:2428330575455103Subject:Computer Science and Technology
Abstract/Summary:PDF Full Text Request
As a typical dynamic programming language,Python is becomming more and more popularity due to its powerful expression ability,flexibility,and sufficient third-party libraries.However,lacking of static type information,many software engineering activities(such as program comprehension,software debugging,and static bug detec-tion)cannot be carried on effectively.To code with this problem,Python community proposed a static type annotation proposal.The proposal allows programmers to anno-tate type hints by comments.These type annotations only indicate the type information in source code,and cannot be parsed by Python interpreter at runtime.Type annotations can be analyzed and utilized by many static analysis methods and tools,such as type inference,to improve the accuracy of analysis.However,the extent to which type annotations can help with type inference,and how developers should annotating types with limited time and resource,have not yet been studied.This article studies the Python type annotation for type inference,focusing on the type annotation effectiveness for type inference and the cost-effective type annotation recommendation.The work in this article includes:· We extend an existing type inference engine to support type annotation.The tool supports an open source annotation set TypeShed as integration of external anno-tations,as well as internal type annotations inside the project.After the type an-notation is integrated,the tool can effectively improve the original type inference results.And Using a open source type annotation collection TypeShed,we con-duct an empirical study to analyze the effectiveness of type annotations on type inference.The experimental results on 11 open source Python projects show that,external type annotations can help improving type inference effectively,and the improvement on local variable type inference is the most significant.· We propose a type annotation recommendation method named TARank,consid-ering the cost-effective of type annotating,to help achieving better type inference result by annotating less variables.The experimental results show that TARank can be applied to the real large Python projects,and the recommended annotations can effectively improve type inference results,and in some scenarios,annotating the variable with higher score helps achieving better type inference result.The results of this article will inspire the future research work on type annotation and type inference,and provide the pratical guidline to annotating types for program-mers with limited time and resources.
Keywords/Search Tags:Python, Data flow Analysis, Type inferrence, Empirical study, Type annotation
PDF Full Text Request
Related items