Open JelleZijlstra opened 2 years ago
I decided on option 2, implemented in #361 and JelleZijlstra/autotyping#25.
It still needs a more convenient interface, but it works:
$ python -m pyanalyze --json-output failures.json pyanalyze/node_visitor.py -v -e suggested_return_type -e suggested_parameter_type
$ python -m libcst.tool codemod autotyping.AutotypeCommand pyanalyze/node_visitor.py --pyanalyze-report failures.json
LibCST would be a better fit for applying changes to the code, like the suggested types from #358. Currently, we have a mechanism that can replace an AST node and decompile it with ast-decompiler, but that's fragile and doesn't preserve comments.
The obvious option would be to use LibCST instead of ast.parse for the whole type checker. However, I'm worried that that will kill performance: running https://github.com/JelleZijlstra/autotyping on our codebase is noticeably slower than running pyanalyze, and pyanalyze has to do a lot more work itself in addition to parsing and running visitors.
Possible approaches:
Either way, we'd use the line and column number to match up ast and libcst nodes.