Static type inference method and system for Python external function

An external function, static type technology, applied in electrical digital data processing, instrument, platform integrity maintenance, etc., can solve problems such as requiring manual assistance, poor type inference accuracy, and inability to effectively handle external functions.

Pending Publication Date: 2022-01-04
UNIV OF SCI & TECH OF CHINA
View PDF0 Cites 0 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

These works often use methods such as directly ignoring (such as treating as object type) or preset type stubs to deal with external objects, and the accuracy of type inference is not good or requires manual assistance.
[0007] It can be seen that the existing deterministic and non-type-based static type inference tools for Python cannot effectively handle external functions

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Image

Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
  • Static type inference method and system for Python external function
  • Static type inference method and system for Python external function
  • Static type inference method and system for Python external function

Examples

Experimental program
Comparison scheme
Effect test

Embodiment 1

[0034] Such as figure 1 As shown, the static type inference method of a Python external function provided by the embodiment of the present invention includes the following steps:

[0035] Step S1: Perform language separation on the Python / C multilingual project; for the C language file obtained after separation, identify the external function declarations therein, and analyze the parameter type conversion and return type conversion realized by the external function corresponding to each external function declaration;

[0036] Step S2: Carry out type inference according to the external function declaration, parameter type conversion and return type conversion, and at the same time check the consistency of the no-argument function declaration for the external function declaration and the corresponding external function implementation.

[0037] Python's foreign function interface Python / C API is an intermediate layer bridging Python and C / C++. Such as Figure 2A The program hos...

Embodiment 2

[0119] Such as Figure 12 As shown, the embodiment of the present invention provides a static type inference system for Python external functions, including the following modules:

[0120] The recognition and analysis module 21 is used to separate the languages ​​of Python / C multilingual projects; for the C language files obtained after separation, identify the external function declarations therein, and analyze the parameter type conversions implemented by the external functions corresponding to each external function declaration and return type conversion;

[0121] The type inference module 22 is configured to perform type inference according to the external function declaration, parameter type conversion and return type conversion, and at the same time check the consistency of the no-argument function declaration for the external function declaration and the corresponding external function implementation.

[0122] Such as Figure 13 As shown, a schematic diagram of the Py...

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

PUM

No PUM Login to view more

Abstract

The invention relates to a static type inference method and system for a Python external function. The method comprises the following steps: S1, performing language separation on a Python/C multi-language project; for a C language file obtained after separation, identifying external function declarations in the C language file, and analyzing parameter type conversion and return type conversion realized by an external function corresponding to each external function declaration; S2, carrying out type inference according to each external function declaration, the parameter type conversion, and the return type conversion, and carrying out parameter-free function declaration consistency check on each external function declaration and the corresponding external function. According to the method provided by the invention, the type signature of an external function can be inferred, and a Python static type inference tool in the prior art is enhanced, so that the Python static type inference tool can analyze external function calling in a program and check vulnerabilities that external function declarations are inconsistent with the implementation thereof.

Description

technical field [0001] The invention relates to the fields of programming language and static analysis, in particular to a static type inference method and system for Python external functions. Background technique [0002] Static type inference is one of the important means to maintain the security of dynamically typed language programs. However, foreign functions implemented in another programming language are often outside the scope of the host language's type inference. As a popular dynamically typed language, Python has a large number of widely used Python packages that are multi-language architectures that include C / C++ external extensions. [0003] Both academia and industry have made a lot of attempts on Python's static type inference. These jobs can be divided into the following three categories: [0004] 1. Support type annotation through extended syntax, and perform type inference based on type annotation. Representative ones include Mypy from the Python commu...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

Application Information

Patent Timeline
no application Login to view more
Patent Type & Authority Applications(China)
IPC IPC(8): G06F8/34G06F21/57
CPCG06F8/34G06F21/577
Inventor 张昱胡明哲
Owner UNIV OF SCI & TECH OF CHINA
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Try Eureka
PatSnap group products