[Dy2stat]support Python3 type annotation #36544
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
PR types
Others
PR changes
Others
Describe
Dy2stat type annotation
背景
python3支持type hint语法,动转静模块中可以借助type hint语法进行变量类型分析。
功能描述
python3中的type hint语法,比如赋值语句
a: float = 1.0和函数参数func(a: int, b: float = 1)。对于下面的代码forward函数虽然将texts标示为paddle.Tensor类型,但是由于动转静模块并未支持python3的type hint语法,无法将texts识别为一个tensor,for语句动转静处理list时会出错。在此PR之后可以将函数参数texts识别为一个tensor。测试
下面是两个测试样例,以及
StaticAnalysisVisitor模块所识别出的变量类型。