Font Size: a A A

Static Type Analysis And Type Error Checking For Python

Posted on:2016-08-01Degree:MasterType:Thesis
Country:ChinaCandidate:T C DongFull Text:PDF
GTID:2428330461457763Subject:Computer software and theory
Abstract/Summary:PDF Full Text Request
Python is an object-oriented dynamic typed language which has a simple grammar and a rich standard library.Now it is popular in many kinds of tasks.However,with a dynamic type system,Python interpreter has to make type checking at runtime.At compile time,Python will not check whether the object has the method called or not,so python has no way to make type error checking at compile time.Also,python cannot offer type information and methods owned by objects.To handle the problems above,this paper makes a static type analysis for Python and applies the results for type error checking at compile time.The method is a suite of solutions which include defining type annotation system which encapsulates the type information and organizes the information into a specific form;transforming the source code to intermediate representation;making type annotation and annotating the built-in modules,classes and functions;making type inference to get the type information of each variable.With type information,we make type error checking at compile time and integrate the information in IDE to assist development.By a case study,we illustrate how to make type error checking step by step.In the experiment,we select some modules from standard library and open source projects from Github as experimental subjects.We evaluate the method of this paper by collecting the data of type set,annotation rate,recall,precision and time cost and so on.The paper has contributions as following:First,transforming the complicated grammar structure into ones with simple form and transforming the complicated statements into a group of simple ones.The preprocessing reserves the information of code structure and provides interfaces for type analysis.Second,constructing a complete type annotation system which encapsulates the type information,the relationships among the types and the operations the types allow.Through type annotation and type inference we can reduce the python source code into the annotation system.Third,getting type information by type annotation and type inference and making type annotation for the built-in modules,classes and functions.Python has a mount of built-in modules integrated in the interpreter which implemented in C language.As the method in the paper is for codes implemented in Python language,we have to transform these built-in modules into Python form before make type analysis.Annotate the classes and functions when they are defined and apply the type inference algorithm based on constraint graph to infer the type information of all the variables.Fourth,making static type error checking at compile time with type information got from type annotation and type inference.At the same time,providing the attribution or methods which objects own for developers.The paper adopts the type error checking algorithm based on the constraints.It can detect the expression errors,method call errors and invalid attribution errors by defining constraints,generating constraints automatically and applying the type error checking algorithm.
Keywords/Search Tags:type analysis, type annotation, type inference, Python
PDF Full Text Request
Related items