Technologicat / pyan

Static call graph generator. The official Python 3 version. Development repo.
GNU General Public License v2.0
329 stars 57 forks source link

Syntax error in debug line #8

Closed matt-kempster closed 5 years ago

matt-kempster commented 5 years ago

This line: https://github.com/Technologicat/pyan/blob/3034deed9d6eed8d7f38a62172cfb80b5de3047e/pyan/analyzer.py#L612 erroneously references filenaame, an attribute that does not exist. Additionally, the line above it mentions values[0] when values cannot be subscripted in some cases. I found success commenting this whole statement out - in fact, my mips_to_c repository is a success story for your support of Python 3.6+ type hinting, so thank you for implementing that!

Technologicat commented 5 years ago

Good catch, thank you, fixed!

(Should have been self.filename.)

matt-kempster commented 5 years ago

Any thoughts on the value[0] thing? I also had to comment that out last time I used this project. Perhaps worth checking if value first.

Technologicat commented 5 years ago

Ah, I missed that, sorry!

I looked at it now. I think it should work in the latest release (1.0.4).

Indeed, value is a single AST node, as documented in GTS. It's also optional. It can be missing, if the statement is used just to declare the type of the target.

However, the helper function sanitize_exprs (in pyan/anutils.py) always wraps a single node in a Python list. This simplifies the calling end, by providing a consistent API to extract the first (sometimes only) AST node from the value, since some constructs support multiple nodes (which are represented as a list in the AST), while others support only a single node (in which case there is no wrapper in the AST itself).

Also, visit_AnnAssign has a check for if node.value is not None, which should cover the case where the optional value is missing. If I recall correctly, I added this check later - it probably was not there in the first attempt to support AnnAssign.

Could you try the latest release (1.0.4), and if it still crashes, provide a short example for testing?