pytype icon indicating copy to clipboard operation
pytype copied to clipboard

annotate_ast.annotate_source gets wrong line number for multi-line list in Python 3.7+

Open maldil opened this issue 4 years ago • 1 comments

I observed following behavior in annotate_ast.annotate_source

The AST annotator correctly annotate the type of _VERSION as str and type of REQUIRED_PACKAGES as List[nothing] in below example.

_VERSION = '1.12.0'
REQUIRED_PACKAGES = []

As the next step, I updated the code as below.

_VERSION = '1.12.0'
REQUIRED_PACKAGES = [
     'absl-py >= 0.1.6',		
     'numpy >= 1.16.0',		    
 ]

It annotates type of _VERSION correctly but it does not annotate REQUIRED_PACKAGES. I checked the AnnotateAstVisitor to find a possible root cause for this behavior. I observed they visit Name nodes. Therefore I believe, it should visit the node REQUIRED_PACKAGES. Any help to debug this error is very much appreciated.

Pytype version : 2021.1.8 OS: MacOS

maldil avatar Jan 23 '21 08:01 maldil

annotate_ast appears to correctly annotate REQUIRED_PACKAGES in Python 3.6 but fail to find an annotation in 3.7, which points to a bug in how we're handling bytecode/line number changes between the two versions. In particular, https://github.com/google/pytype/blob/7056acd733ea88eef084c90b6bb8c56d74c7096d/pytype/tools/traces/traces.py#L255-L258 looks extremely suspicious to me.

rchen152 avatar Jan 26 '21 07:01 rchen152